Search Unity

Connection to other scripts

Discussion in 'Scripting' started by nick5556, Jul 25, 2011.

  1. nick5556

    nick5556

    Joined:
    Apr 27, 2010
    Posts:
    30
    Hello,

    I wanna make a connection between my playerController and my EnemyAI script, and i don't know where it's going wrong!

    This is the snippet:

    Code (csharp):
    1. if(curTarget != null) {
    2.     var eAI : EnemyAI = curTarget.GetComponent("EnemyAI");
    3.        
    4.         GUI.DrawTexture(Rect(0,150,500,150), EnemyGUI);
    5.        
    6.         GUI.Label(Rect(201,39,228,17), eAI.monsterName);
    7. }
     
  2. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    Neither do I. A good start would be describing what you want the code to do and what it is actually doing - how it is failing.
     
  3. RicheyMB

    RicheyMB

    Joined:
    Jul 20, 2009
    Posts:
    111
    My guess would be that curTarget does not have a EnemyAI component attached. I would check for eAI being a null value before doing anything with it. If it's not null and you can't get .monsterName then maybe that is not set.
     
  4. zine92

    zine92

    Joined:
    Nov 13, 2010
    Posts:
    1,347
  5. nick5556

    nick5556

    Joined:
    Apr 27, 2010
    Posts:
    30
    Solved, i had two scripts with the name EnemyAI