I want clicking and/or touching a certain game object on the scene to change the color of another game object. So far I am able to use the mouse and keyboard for this with the script below.
using UnityEngine;
using System.Collections;
public class ColorChanger : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
if (Input.GetMouseButton (1))
{
gameObject.GetComponent<Renderer>().material.color = Color.green;
}
if (Input.GetKeyDown (KeyCode.P))
{
gameObject.GetComponent<Renderer>().material.color = Color.magenta;
}
}
}
But I want to be able to click on another game object to change this. I have searched the Scripting API but have been unable to find something to do this. Any help would be appreciated!