- Home /
Question by
xikky · Mar 08, 2013 at 04:42 PM ·
perfomance
Performance question: Accessing public variables.
private var PlayerScript:Player;
function Start () {
PlayerScript = playerTransform.GetComponent(Player);
}
function Update () {
if (PlayerScript.check){
//do stuff.
}
}
This is just some pieces of my code. When I try to access a public variable, like in the if statement above, PlayerScript.check, would this drain down performance, even if I access such variable multiple times in an update function?
Comment
Best Answer
Answer by whydoidoit · Mar 08, 2013 at 05:12 PM
You are fine doing that - just don't call GetComponent in the Update function.
Yes, this is actually a very good way of doing things since you cache the reference to PlayerScript and don't have to look it up every time.