Ok so i have my character going around and he his supposed to get life whenever he hits a Tool Tool Box. Anyway, i'm trying to display my character life but something it isn't right...
In the tool box i have this script called TesteTool.js:
P.S. - Vida means life in Portuguese.
Well i know life was supposed to be attached to the character but it doesn't matter in this case. Well on the other hand i have a script attached to the camera with this:
Well now everything works fine and when i press play i get the life showing on my left corner, hmmm, almost. When i go into the tool box i get a NullReferenceException error. Why is that and how can i fix it?
Oh and by the way, just for curiosity, but what happens if i have more than one object with the same name in the hierarchy? I mean, when i ask to get the component of the object with that name? And this is not always fixable, because, in example, when you instantiate prefabs along the scene they all get the same name. Am i missing something here?
Glad to be among such nice people like you guys. Please help me. ;) Thanks.
Try to use static typing:
your var videOnGui is not typed.
weirdly pragma strict should not let you go.
Try to use :
The other one works because you provide an additional info:
Unity sees 10 and knows it is an int.
Edit: Try this:
Let it be, i just figured it out. Actually, i deleted almost everything and did it the opposite way, i was being so stupid doing things this way, so i tagged my toolbox prefab and then putted them wherever i wanted. Then attached the script to my character(is a tank), and set it to display the life in the update of that character... Solve 3 problems in one script... eheheh, Thanks a lot for the help fafase. :D