Hi, I know this is an annoying question but I can't find an exhaustive answer on forum. I want do a script that on touch (mobile Device) change the material of an object. If it possible i should have button (or buttons) on gui that when pressed change the material of the object. If someone have an example or tutorial of this it wil be fantastic. Tank You
I suggest breaking your search down into its separate parts. 1 - How to change a material with a script. 2 - How to select an object. 3 - How to script a button. Here are the scripting reference pages that will also get you there. http://docs.unity3d.com/Documentation/ScriptReference/Renderer-material.html http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnMouseDown.html http://docs.unity3d.com/Documentation/ScriptReference/GUI.Button.html
Hi, I'm trying but no result. I think it's simple but I'm new to Unity. I have a simple scene with one sphere, one plane and two materials, A and B. This is the script I've create: Code (csharp): using UnityEngine; using System.Collections; public class SwitchMat : MonoBehaviour { var Sphere; var A; var B; // Use this for initialization void Start () { Sphere = GameObject.Find("Sphere"); } // Update is called once per frame void Update () { if (GUI.Button (new Rect(0, 0, 100, 20), "RED")) GameObject.renderer.material = A; if (GUI.Button (new Rect(0, 30, 100, 20), "GREEN")) GameObject.renderer.material = B; } } But I have no results.