-1

My Raycast is working and hitting my Enemy.

But if I hit him, I want to change the health variable in the other script of the hit Object (Enemy Controller) by calling the TakeDamage(damage) function.

Unfortunately, I get this error:

"Assets/Weapons/FPS Weapons/Scripts/Gun_Controller.js(692,35): BCE0018: The name 'EnemyController' does not denote a valid type ('not found'). Did you mean 'System.ComponentModel.EnumConverter'?"

Here's my Code:

if (hit.transform.tag == "warzombie_01") {

    // Impact Particle for Enemy - warzombie_01
    var impactHitBlood: GameObject = Instantiate(impactEffectBlood, hit.point, Quaternion.LookRotation(hit.normal));

    Destroy(impactHitBlood, 0.5 f);

    //var enemyController : EnemyController = hit.transform.gameObject.GetComponent.<EnemyController>();

    var enemyController: EnemyController = hit.transform.GetComponent(EnemyController);

    if (enemyController != null) {

        enemyController.TakeDamage(damage);
    }

}

Thanks!

yuriy636
  • 11,171
  • 5
  • 37
  • 42
1zz0
  • 264
  • 3
  • 18
  • Are you sure this is JavaScript? Or does Unity enforce types in JS? -- Ah. You might want to add the `UnityScript` tag. – evolutionxbox Sep 06 '17 at 17:25
  • It is still some kind of Javascript but UnityScript tag is better used for this. – Programmer Sep 06 '17 at 17:29
  • @1zz0, This problem only happens with UnityScript. Consider switching to C#. Another reason to switch to C# is because UnityScript is now [discontinued](https://stackoverflow.com/questions/45523239/is-unityscript-javascript-discontinued). Its compiler will be removed from Unity in the future. Save yourself time now. – Programmer Sep 06 '17 at 17:32

1 Answers1

0

Ok i found out the problem. My "Enemy Controller" should be in the following folder: Assets > Standard Assets.

1zz0
  • 264
  • 3
  • 18