I was making a 3d game and I wanted to add the health value number when you collide with the coin.
You can add an increment to the health value within the OnTriggerEnter function. There’s a great tutorial on the Unity site https://unity3d.com/learn/tutorials/projects/roll-ball-tutorial for collecting cubes. You could implement the increment in a number of ways:
**adapted from mentioned tutorial**
//declare health variable int
public int healthValue;
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag ("Pick Up"))
{
other.gameObject.SetActive (false);
// perform the increment +1
healthValue++;
}
}
or if you want to do it a set amount each time
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag ("Pick Up"))
{
other.gameObject.SetActive (false);
// perform the increment +30
healthValue += 30;
}
}
I hope that helps