- Home /
guitexture a static var?
can a guitexture be a static var? I am trying to access a guitexture that in in another js file. I made it a static variable but am not having any luck. Is this even possible?
I need code to be added to update function so it can checked to see if a boolean is true or false constantly throughott he game. any other suggestions. I am using javascript.
function Update(){
if(FrontDoorExt.check==true) {print("test"); } }
//FrontDoorExt is the name of the js that is storing the boolean. // There is a guitexture in it that is enabled. But i keep getting an error that says "an instance type of "FrontDoorExt" is required to access non static member var "check"
Answer by vdizzle · May 15, 2010 at 01:19 AM
var myGUI: GUITexture=gameObject.GetComponent(GUITexture);
Answer by qJake · May 11, 2010 at 04:09 AM
Why don't you just get its reference from the other Game Object?
// C#
GUITexture gt = GameObject.FindObjectOfType(typeof(GUITexture)) as GUITexture;
gt.DoSomething(); // whatever you want here
(Note that that code should NOT be placed inside of an Update() function, and will ONLY find the first GUITexture you have.)
Or, instead of using FindObjectOfType(), you could also:
- Find the game object by name
- Find the game object by type
- Store a reference to the game object at design-time, by including
public GameObject myObject;
Then, fill it in in the Inspector.
Then, you could just get the component from the game object like so:
// C#
GameObject go; // make this reference your target game object somehow
GUITexture gt = go.GetComponent(typeof(GUITexture)) as GUITexture;
gt.DoSomething(); // whatever you want here
Your answer
Follow this Question
Related Questions
Static variables heavy for the iphone's CPU? 3 Answers
simple coding problem 1 Answer
Trying to add 1 point to score, but it is adding 2. 2 Answers
Spawning objects on trigger does not work as expected 2 Answers
Problem with static variables 1 Answer