|
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.
(comments are locked)
|
|
Try to use static typing: var some:int; 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: Ok, thanks a lot, now the error is gone, but still the life isn't being updated on the gui box, it does in the console but not int the box. Can you help me on that aswell? Don't worry, when my question is fully filled i'll mark your answer as correct. Just wan't to ask you aswell to vote up in my question just for the matter that i'm doing a work for college in unity and since i'm new here, i have to wait for my questions to be accepted in the queue before being submitted, would you help me out getting those 15 points by voting in my question? Most appreciated. :D Thanks a lot.
Jul 09 '12 at 08:33 PM
Satamanster
Hmmm. Your code worked, i do understand it, i just don't get why does that work and mine doesn't. if you can explain me that it would be great. Now just one left thing to go... Remember that question i made at last in my post... Well it matters here because, imagine, if i duplicate my toolbox now, and you press play. Imagine you life starts at 50, after i hit the first toolbox it updates to 70, but after you hit a second one, nothing occurs. Do you have a solution for me please? :D Thanks again.
Jul 09 '12 at 08:57 PM
Satamanster
(comments are locked)
|
|
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
(comments are locked)
|

I don't know if it helps but debug.logging the life returns that when i enter the trigger the life keeps updating +20 forever...