x


Why can't I change the Texture of my GUITexture?

Hey there,

I have an array containing two Texture2Ds, I want to be able to change the Texture2D of the GUITexture that I am instantiating, here is the code I am using:

var n = Random.Range(0,2);
Debug.Log("N : " + n);
var scoreAlert = Instantiate (scoreMessage);
scoreAlert.texture = scoreMessageTexture[n];

However I always receive the error 'texture' is not a member of UnityEngine.Object

more ▼

asked Mar 20 '11 at 01:52 AM

T. gravatar image

T.
159 22 26 34

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

1 answer: sort voted first

Instantiate returns Object; you need to cast it to GUITexture.

var scoreAlert = Instantiate (scoreMessage) as GUITexture;
more ▼

answered Mar 20 '11 at 02:25 AM

Eric5h5 gravatar image

Eric5h5
80.3k 42 132 521

(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:

x2210
x1683
x478

asked: Mar 20 '11 at 01:52 AM

Seen: 1093 times

Last Updated: Mar 20 '11 at 01:52 AM