Search Unity

The type or namespace ' could not be found

Discussion in 'Editor & General Support' started by wicxxk, Aug 18, 2019.

  1. wicxxk

    wicxxk

    Joined:
    Aug 18, 2019
    Posts:
    1
    Hello, so I'm stuck with a problem with this error. I have two scripts: Attack and enemyMovement and a object called Enemy. On enemyMovement there's a method called Damaged:

    Code (CSharp):
    1. public void Damaged(int damage)
    2.     {
    3.         if(!isDead)
    4.         {
    5.             isDamaged = true;
    6.             currentHealth -= damage;
    7.             anim.SetTrigger("HitDamage");
    8.             if(currentHealth <= 0)
    9.             {
    10.                 isDead = true;
    11.                 rb.AddRelativeForce(new Vector3(3, 5, 0), ForceMode.Impulse);
    12.             }
    13.         }
    14.     }
    On Attack, the coding is:

    Code (CSharp):
    1. public class Attack : MonoBehaviour
    2. {  
    3.     public int damage;
    4.  
    5.     // Start is called before the first frame update
    6.     void Start()
    7.     {
    8.        
    9.     }
    10.  
    11.     // Update is called once per frame
    12.     void Update()
    13.     {
    14.        
    15.     }
    16.  
    17.     private void OnTriggerEnter(Collider other)
    18.     {
    19.         Enemy enemy = other.GetComponent<Enemy>();   //this is the line with error, on both "Enemy" 's
    20.         if(enemy != null)
    21.         {
    22.             enemy.Damaged(damage);
    23.         }
    24.     }
    25. }
    But still, the error says: error CS0246: The type or namespace name 'Enemy' could not be found (are you missing a using directive or an assembly reference?)
    I tried a lot of stuff to solve it but been stuck with it for hours, don't really know what to do :/
     
  2. ibbybn

    ibbybn

    Joined:
    Jan 6, 2017
    Posts:
    193
    Maybe I misunderstand but are you trying to reference a gameobject with the name "Enemy" with getcomponent ?
    Just rename your script file and class enemyMovement to Enemy?