- Home /
Accessing other script's variable into another script
i wonder what is wrong with my code..
i get this error:-
NullReferenceException: Object reference not set to an instance of an object _Crate.Update () (at Assets/Sample Assets/2D/Scripts/_Crate.cs:22)
can anyone help me here? my _Player script has only a public int variable ..
Hi $$anonymous$$rHero, can you post your code as text and format with the 101010 button, not as an image, thanks :)
Your code will only work if the _Player component is on the same game object as this script. And I second @$$anonymous$$rSoad's request. Please don't post scripts as images.
@$$anonymous$$rSoad: Thanks for the info.
@Jeff $$anonymous$$esselman: Ohh thanks !! one more question, so this script is attached to a prefab, what if i wanted to make another type of crate? it will still need the player script to be there? what if there is more than 50 different enemies will i have to attach my player script to all of them?
Thanks againn ^^
@robertbu yeh I'll do that, but what if i want it to run without _Player being a component of the script?
Ya you can do it By putting it on a single game object in scene and make this _Player class singleton.
Your answer

Follow this Question
Related Questions
NullReferenceException: Object reference not set to an instance of an object 1 Answer
Object Reference Not Set Up As An Instance Of An Object 1 Answer
help! i want to speed faster ,don't want to change position length .. 1 Answer
Bug in Object reference ? 0 Answers
Script on 3d model gives me NullReferenceException 0 Answers