Search Unity

Help please .....

Discussion in 'General Discussion' started by CapitalGains, Nov 15, 2019.

  1. CapitalGains

    CapitalGains

    Joined:
    Nov 15, 2019
    Posts:
    2
    28095E87-19BE-4644-A925-7222BAC593E1.png

    Can anyone help with this? Very new to this, but no matter what variable I try to pass from one script to another I get the null alert of death... Even when successfully passing the method or variable through.
     
  2. DimitriX89

    DimitriX89

    Joined:
    Jun 3, 2015
    Posts:
    551
    Are both scripts on the same object? Because if no, I believe you'll need a reference to ship's gameObject to search in it
     
    Ryiah and CapitalGains like this.
  3. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987
    You might have another gameobject with that enemy script on it that you forgot about. Put Debug.Log("random text", this); in the Enemy scripts Start method and see how many get logged, then click on the log in the console and it will show you the object in the scene.
     
    Ryiah and CapitalGains like this.
  4. CapitalGains

    CapitalGains

    Joined:
    Nov 15, 2019
    Posts:
    2
    You guys are awesome. For simplicity I just deleted my second game object “enemy ship” and made sure both scripts were on my only game object “ship”. This solved the error. I must have had the script attached to both ships. I found the solution to be create an empty game object as a communicator between the enemy and ship. Then I declared the two classes in the communicator. Then rather than use get.component I use the inspector and drag the ship and enemy into the declared variable classes on the communicator. It appears as though this gives me access to all the variables from the two classes in one script. Thanks fellas
     
    HiddenMonk likes this.