x


Changing the texture on an object with a trigger.

I wondered if there was a simple way to change the texture on an already textured object using a trigger?

With something similar to this which has worked with playing animation with an invisible trigger, but how do I code to change the texture once the trigger has been activated?

 function OnControllerColliderHit (hit : ControllerColliderHit)
{
if (hit.gameObject.tag == "Cube")

Getmaterial.object == "From File)

The Get material is only a guess, but does anyone have an answer?

more ▼

asked Nov 29 '10 at 10:47 PM

Rukey4 gravatar image

Rukey4
3 3 4 8

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

1 answer: sort voted first

Crate an folder named "Resources" in your assets.(If you don't have one) Put your texture in that folder. (For example "TextureName.png") And call this on the trigger:

renderer.material.mainTexture = Resources.Load("TextureName");
more ▼

answered Nov 29 '10 at 11:20 PM

IJM gravatar image

IJM
1.4k 2 5 19

Thanks very much! Just what I wanted, would it be much more complicated to choose which texture it replaces. For example one of my objects will have the main texture and will have a black / white image texture so it looks like text is carved into the object (similar to a gravestone). Is there an easy way to change the black / white image rather than the main overall texture.

But if not this has been very much appreciated!

Nov 30 '10 at 10:31 AM Rukey4

Google for "Unity SetTexture". Oh, and please accept my answer =D

Nov 30 '10 at 02:57 PM IJM
(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:

x3443
x2188
x1089
x72

asked: Nov 29 '10 at 10:47 PM

Seen: 1522 times

Last Updated: Nov 29 '10 at 10:47 PM