x


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?

more ▼

asked May 11 '10 at 03:43 AM

vdizzle gravatar image

vdizzle
57 9 10 15

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.

May 11 '10 at 11:50 AM vdizzle

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"

May 11 '10 at 12:48 PM vdizzle
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

var myGUI: GUITexture=gameObject.GetComponent(GUITexture);

more ▼

answered May 15 '10 at 01:19 AM

vdizzle gravatar image

vdizzle
57 9 10 15

(comments are locked)
10|3000 characters needed characters left

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
more ▼

answered May 11 '10 at 04:09 AM

qJake gravatar image

qJake
11.6k 43 78 161

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x477
x277
x109

asked: May 11 '10 at 03:43 AM

Seen: 1578 times

Last Updated: May 11 '10 at 03:43 AM