Hi there. I am working on a little game as a first time project and am having a bit of trouble doing what’s probably quite a simple thing to do. Basically i have a set of squares which i want to change colour on a click of the mouse. The script i created also checks to make sure that this can’t be done twice. It works fine with one square, but as soon as i have more than one square it selects them all simultaneously. Here is my script:
using UnityEngine;
using System.Collections;
public class A1 : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(gameObject.renderer.material.color!=Color.red && gameObject.renderer.material.color!=Color.blue)
{
ColourChanger();
}
}
void ColourChanger()
{
if (Input.GetMouseButtonDown (0)) {
gameObject.renderer.material.color = Color.red;
}
if (Input.GetMouseButtonDown (1)) {
gameObject.renderer.material.color = Color.blue;
}
}
}
What i want is for to be able to change only one of the squares. I think that it’s a prob with the ‘Input.GetMouseButtonDown (0)’ part as it’s too general and will effect everything no matter where i press the mouse button. Can anybody help me? Thanks