x


Multiple Materials

Greetings,

I have been working for along time, to figure out how to add multiple materials, to an object through scripting.

Example;

I have an object, cube, and its green from its material! I want to make it so that when I click it there is an new material added to it, whit an transparenty texture, so that has yellow edges! But it doesnt stop here, I also want another material over that again, so it makes it have red circle in the middle, again, transparenty texture!

I know how to script the code to check when I am clicking it, I just use "OnMouseUp", put, how can I be able to add multiple materials through that script?

It would be much appreciated if someone could lend me, a hand!

Thanks in advance!

Best Regards, M!

more ▼

asked Jul 30 '12 at 07:01 PM

winsjansen gravatar image

winsjansen
13 4 6 7

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

1 answer: sort voted first

MatChanger.cs

using UnityEngine;
using System.Collections;

public class MatChanger : MonoBehaviour
{
	public Material[] Materials;
	void OnMouseUp()
	{
		renderer.material = Materials[UnityEngine.Random.Range(0, Materials.Length)];
	}
}
more ▼

answered Jul 30 '12 at 10:07 PM

ScroodgeM gravatar image

ScroodgeM
7.6k 2 6

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

x838
x272

asked: Jul 30 '12 at 07:01 PM

Seen: 455 times

Last Updated: Jul 30 '12 at 10:07 PM