How I can assign an empty object to static (Transform) variable ??
There is two variables in my script that I don't want to make them static ,but the problem is : that two variables are exist in static function so unity displays an error if I didn't make them static. Now I want to assign two objects to that two variables ,so I wrote this code(I uploaded it as attachment), but I got this error : An instance of type 'UnityEngine.Component' is required to access non static member 'transform'.link text
Thanks ^^
Please, paste the code directly inside the question, it can't be read as an attachment
//Variables :
public static var NitrosBtn : Transform ;
public static var HelpfulBtns : Transform ;
public static function SetVar () {
NitrosBtn = Resources.Load("NitroBtn");
HelpfulBtns = transform.Find("HelpfulBtn");
Answer by Rob-Fireproof · Feb 29, 2016 at 04:15 PM
The problem is that you're trying to access the non-static variable (transform) from inside a static function. Since "transform" can have a different value for each instance of your class, you can't access it in a static function. It has no way to know which instance's transform you're asking for.
If you really need to keep that function static, you can use GameObject.Find instead, which is a static function.