Hello, after few days I gave up and came to you guys ![]()
What I am trying to do is:
In Script 1 I want to compare variable:
if(Variable WOOD from Script2 >= 50)
DoSomething
In Script2 which is attached to another object I have variable WOOD.
var WOOD = 100;
I need to compare Variable wood I tried to ask my friend, I searched whole google, Found few posts tried every one of them Still the same Error:
NullReferenceException: Object reference not set to an instance of an object
Pleasee help
It did not find that object in a scene. I tried: if(script2) Debug.Log("Found"); else Debug.Log("did not found"); and ofc it printed did not found.
– WrymnBe sure to replace "Script2" in my example with whatever the name of your script is.
– whebertOf Course I did I am not that stupid :) This is really paranormal activity jesus, how that it is not working? Impossible.
– WrymnSorry, was not implying you were. :) And you're sure there is a game object with your second script attached in the scene? That should work then... You could put Debug.Log statements in the Start function of you scripts just to verify they are in the scene and active, "Script 1 started", "Script 2 started", etc.
– whebertYes they start I put I can show you the script: Script1 attached to empty game object function Update () { var script2 : Resources = FindObjectOfType(Resources); if(Input.GetButtonDown("Q") && script2.WOOD >= 50) { Instantiate(Structure, transform.position, transform.rotation); } } Resources Script attached to another empty game object: var WOOD : int = 100; function Update () { WoodGUI.text = "Wood: " + WOOD; }
– Wrymn