My problem is: I have written a C# script which allows me to switch between different materials. The materials are used on several different game objects. When I control the switching by the function: if (Input.GetKeyDown(KeyCode.K)) everything works fine. All the game objects change their material.
Now, when I want to use a GUI button: if (GUI.Button (new Rect (10,10,150,100), “button”)) to control the switching of the materials it works only on 1 game object not on all as it is desired.
Can anybody tell me why this happens or how I can manage this problem???
Thanx to everyone!!!
Aljoscha
using UnityEngine;
using System.Collections;
public class SWP2 : MonoBehaviour {
public Material[] mats;
public GameObject ga;
private int index = 0;
// Use this for initialization
void Start () {
ga.renderer.material = mats[index];
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.K))
{
index++;
if (index > mats.Length - 1)
{
index = 0;
}
ga.renderer.material = mats[index];
}
}
}