I want to make it so that when two objects collide, a 3D text object changes it’s color. I’ve tried to do this with both
textObject.GetComponent<TextMesh>().color =Color.white;
and
textObject.GetComponent<Renderer>().material.color ==Color.white
Neither of these seem to work… Does anyone know how to perform what I’m trying to do? Any and all help appreciated 
using UnityEngine;
using System.Collections;
public class TestScript : MonoBehaviour
{
public GameObject textObj;
private float lastChangeTime;
public float changeDelay;
void Start()
{
lastChangeTime = Time.time;
}
void Update()
{
if(Time.time > lastChangeTime + changeDelay)
{
Color newColour = new Color(Random.Range(0f, 1f),Random.Range(0f, 1f), Random.Range(0f, 1f), 1);
Debug.Log(newColour);
textObj.GetComponent<TextMesh>().color = newColour;
lastChangeTime = Time.time;
}
}
}
top one works fine… there is a caveat on the scripting page:
1 Like