I have the fps controller with a cube attached, when it runs into my object, the object turns green and is supposed to add 1 to the score board (the score board is just a text UI). I have 5 objects and when I run into the first object, it adds 1 to my score but when I run into the second object it stays at the same score from the first object. I did have it working just fine but than something happened. I want my score to go up every time I run into a object not just once.
here is the code for the object I run into
void Start ()
{
collect = 0;
Tcount();
}
void OnCollisionEnter(Collision col)
{
if (col.gameObject.name == "Cube" && gameObject.GetComponent<Renderer>().material.color == wHite)
{
gameObject.GetComponent<Renderer>().material.color = gReen;
collect = collect + 1;
Tcount();
}
}
void Tcount()
{
collectText.text = "Objects touched: " + collect.ToString();
}
}