viewimage.php?id=2abcdd23dad63db0&no=24b0d769e1d32ca73cec86fa11d0283110260b998d7cfa8997b9266521891b72ef491aee60262314587e71d9990f1a4bfc26a6816a484cc0493887bfb8



using System.Collections;

using System.Collections.Generic;

using UnityEngine;


public class bandit_prac : MonoBehaviour

{


ย  ย  public Animator animator;


ย  ย  public Transform attackPoint;

ย  ย  public LayerMask enemyLayers;


ย  ย  public float attackRange= 0.5f;

ย  ย  public int attackDamage= 40;



ย  ย  void Update()

ย  ย  {

ย  ย  ย  ย  if (Input.GetKeyDown(KeyCode.Space))

ย  ย  ย  ย  {

ย  ย  ย  ย  ย  ย  Attack();

ย  ย  ย  ย  }

ย  ย  }


ย  ย  void Attack()

ย  ย  {

ย  ย  ย  ย  //play an attack animation

ย  ย  ย  ย  animator.SetTrigger("Attack");


ย  ย  ย  ย  Collider2D[] hitEnemies = Physics2D.OverlapCircleAll(attackPoint.position, attackRange, enemyLayers);


ย  ย  ย  ย  foreach(Collider2D enemy in hitEnemies)

ย  ย  ย  ย  {

ย  ย  ย  ย  ย  ย  enemy.GetComponent<Enemy>().TakeDamage(attackDamage);

ย  ย  ย  ย  }

ย  ย  }



ย  ย  void OnDrawGizmosSelected()

ย  ย  {

ย  ย  ย  ย  if (attackPoint== null)

ย  ย  ย  ย  ย  ย  return;


ย  ย  ย  ย  Gizmos.DrawWireSphere(attackPoint.position, attackRange);

ย  ย  }


}



์ฝ˜์†” ์ฐฝ์—๋Š”

NullReferenceException: Object reference not set to an instance of an object

bandit_prac.Attack () (at Assets/bandit_prac.cs:34)

bandit_prac.Update () (at Assets/bandit_prac.cs:21)


์ด๋ ‡๊ฒŒ ๋‚˜์˜ค๋Š”๋ฐ ๋ญ๊ฐ€ ๋ฌธ์ œ์ธ๊ฐ€์š”?? ์–ด์ œ๋ฐค๋ถ€ํ„ฐ ๊ณ„์† ์ฐพ์•˜๋Š”๋ฐ๋„ ๋‹ต์ด ์•ˆ๋‚˜์˜ค๋„ค์š”