|
Hello, I have an object that the player must hit, the object needs to be hit 3 times for something to happen, I want to be able to have several of these objects in my scene. The problem I am having is referencing this hit value from another script. The object I am hitting has a script to detect collisions, while another object has the scripts that are controlling its behaviour. I need to be able to get the hit counter from the collisions script.
(comments are locked)
|
|
This is covered in the docs: http://unity3d.com/support/documentation/ScriptReference/index.Accessing_Other_Game_Objects.html I receive a NullReferenceException when I try to run the game, I am using this code; maledictorHealth = transform.Find("Maledictor").GetComponent(MaledictorHits).hits;
Aug 01 '10 at 12:58 PM
Troy
Is the script on 'Maledictor' really called
Aug 01 '10 at 01:47 PM
e.bonneville
Make sure an object with the named, and capitalized "Maledictor" actually exists when the line is run. If this is true, then try running: if (!transform.Find("Maledictor")) { Debug.LogAlert("Maledictor was not found!"); } If you get the warning "Maledictor was not found" in the log, then you may have mispelled Maledictor. If you don't get that error, try it again, but replace !transform.Find("Maledictor") with transform.Find("Maledictor").GetComponent(MaledictorHits). If you get a not found, then you may have misspelled the script name.
Aug 02 '10 at 03:41 AM
Flynn
Finally, if you do not, I'm not sure what is going wrong.
Aug 02 '10 at 03:43 AM
Flynn
(comments are locked)
|
|
make that variable as public static. in another script acees though classname.varname
(comments are locked)
|
|
Ok, so I have tried to work with this script to get a variable out of another script... Graphics is the object GUIButtons is the script test is the variable in the script I want to get the value of
nothing I am doing is working. ANY help would be great! Post this as a new question - it's confusing to post a question as an answer to another question!
Nov 30 '11 at 11:57 PM
aldonaletto
(comments are locked)
|
