Hello, I have a problem, I want a red cube to change color to yellow when it collisions with a capsule. So i did this:
using UnityEngine;
using System.Collections;
public class collisionpill : MonoBehaviour {
public Color mycolor;
void OnCollisionEnter(Collision other) {
if (other.transform.tag == "Pill") {
transform.GetComponent<Renderer> ().GetComponent<Material> ().color = mycolor;
}
}
So I assigned the “public color mycolor” to yellow. It doesn’t give me any errors, but when my cube collisions with the pill it says: "There is no material attached to the cube, but a script is trying to access it. You probably need to add a Material to the GameObject “cube”.