タワーディフェンス講座_攻撃範囲に侵入された時
- 記述したコード
- This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Weapon : MonoBehaviour { //この武器の攻撃範囲 public float attackRange = 3f; void Start() { //プレイ開始時に数値を合わせる GetComponent<CircleCollider2D>().radius = attackRange; } void Update() { } private void OnDrawGizmos() { //円のギズモ(発生位置:半径) Gizmos.DrawWireSphere(transform.position, attackRange); } private void OnTriggerEnter2D(Collider2D collision) { //攻撃範囲に入ったときの処理 if (collision.CompareTag("Enemy")) { Debug.Log("攻撃範囲に入りました"); } } private void OnTriggerExit2D(Collider2D collision) { //攻撃範囲から出たときの処理 if (collision.CompareTag("Enemy")) { Debug.Log("攻撃範囲から出ました"); } } }
YouTubeでゲーム開発系の動画上げてます