- Home /
small script problem
public var curwp : Transform; public var open : Transform[]; var bestrate: float = 10000; var val : Transform; function Start () { var open = GetComponentsInChildren.<Transform>(); }
function LateUpdate () { bestrate = 10000; //print ("q"); for (var val : Transform in open){ <------ hear print ("a"); var ratesorce = val.GetComponent ("score"); if (ratesorce.ttlscr < bestrate){ bestrate = ratesorce.ttlscr; print (bestrate); } } }
ime doing a script for path finding and it works without error message however it dose not print or do anything past the marked place
Answer by sneftel · May 09, 2011 at 03:12 PM
By using var open
in Start
you're redeclaring open
as a local variable, rather than using the open
declared in your behavior.
k tx i now have a problem with the if statement. (ratestore.ttlscore < bestrate)
and comes up with a mesige object reference not set any solution ??
I couldn't understand any of that. $$anonymous$$aybe you could use real words and sentences?
Answer by Bunny83 · May 09, 2011 at 04:14 PM
First of all, don't post the same question 3 times!
Second, Sneftel told you what you've done wrong, but it seems you don't have a clue what he's talking about. That's a basic logical error. You should learn some basics about programming and the scope of variables.
open is declared as public variable in your script, but in Start you declare a new local variable also called open. You want to assign the result of GetComponentsInChildren to your public variable so remove the var keyword inside Start.
It seems the same goes for your val variable. In this case you just need the local variable that is declared inside your for-loop.
public var curwp : Transform; public var open : Transform[]; var bestrate: float = 10000;
function Start () { open = GetComponentsInChildren.<Transform>(); }
function LateUpdate () { bestrate = 10000; //print ("q"); for (var val : Transform in open){ print ("a"); var ratesorce = val.GetComponent ("score"); if (ratesorce.ttlscr < bestrate){ bestrate = ratesorce.ttlscr; print (bestrate); } } }
Your answer
![](https://koobas.hobune.stream/wayback/20220613132924im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Random Invalid AABB inAABB error 2 Answers
Unidentified error 3 Answers
GameObjects missing from compiled game 1 Answer
ExecutionEngineException: Attempting to JIT compile method 0 Answers
Error while using Facebook sdk and google Admob ad plugin 1 Answer