- Home /
Question by
Eric_Sanjaya · Mar 07, 2014 at 05:58 PM ·
c#getcomponentstatic-variables
GetComponent or static variable faster?
Hello, I have some things that old question in my head. I am using C #. which is actually faster to use static variables or getcomponent?
//example using getcomponent:
public GameManager gameManager;
void Awake()
{
gameManager = GameObject.FindGameObjectWithTag ("GameManager"). GetComponent ();
}
//for next i acces script GameManaget via variable gameManager.
//example using static variabel :
public static GameManager gameManager;
public int score = 0;
void Awake()
{
gameManager = this;
}
//in other script
GameManger.gameManager.score = 1;
which is actually faster?
Comment
Answer by alone1992 · Sep 26, 2014 at 03:29 PM
You can test it yourself , with a simple debug.log and two different variables :D
Your answer
![](https://koobas.hobune.stream/wayback/20220613135634im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How getting transform of another GameObject C#? 1 Answer
Getcomponent what do i wrong? 2 Answers
how to disable/enable a script in c#? 2 Answers