|
ok guys this is what I have pertaining too this specific function except I have a variable called isstuned saved in the file PlayerScript and it is marked as a public int variable this is the new compile error I am getting when I hit play to test the game
my question is how do I set it to an instance of an object? or is that not what I am supposed to be doing at all?
(comments are locked)
|
|
The problem is in the PlayerAnimation.cs script, at line 24. What is in that line? if(Pscript.isstuned == 0) ? If so, the problem is that GetComponent is not finding the script PlayerScript, and when you try to use isstuned Unity complains because Pscript == null. If PlayerScript is in another object, you must first find that object, then get the script. If the PlayerScript is attached to the Player object: The Player object must not be a child of other object, or Find will not find it. the game object containing the variable isstuned is the parent of the object with the script I'm working on :)
Jul 11 '11 at 12:06 AM
deeredman1991
nvm I figured it out :D ty ^_^ ur awesome dude you've answered 3 of my questions and gotten correct answer on all of them...you've always explained things the simplest and effective way possible...keep it up :D
Jul 11 '11 at 12:12 AM
deeredman1991
finally I found the correct answer for the how to access other variables in other scripts after 3 hours searching through all Q/A of how to access other variables in other scripts you answered my Q 2 times 1. actively 2. time passively I'm going to make a Q to make a better manual for this Question I would thumbs up if I could tho :)
Jan 19 at 03:35 AM
sdgd
(comments are locked)
|
|
GetComponent will return null when there is no such Component on the GameObject. Are you sure that you have the PlayerScript attached to the same GameObject as this script above? If you want them on seperate GOs you have to call GetComponent on the right GameObject. eg. In this case you have to assign the other GameObject to the public variable playerObject in the inspector. It would be easier to directly setup a reference to the PlayerScript. Like in the first example just drag the playerobject onto the variable. Unity will automatically link the PlayerScript instance (if there is one) from that GameObject to the variable. If the objects are all instantiated at runtime you have to find the right one either by saving the created instance somewhere when you instantiate it, or use one of the search functions like GameObject.Find / FindObjectOfType / ...
(comments are locked)
|
