Hey guys,
I’m trying to make a scoring code for a project. I’d like to make it so that different tagged objects add or subtract from the score depending on which bin they land in. Right now when an object falls in the bin it adds or subtracts 1 from the score. I’d like to make it so that if Target 1 falls in Bin 1 then it adds 1, but if Target 2 falls into Bin 1 then 1 is subtracted from the score. Here is my code so far.
Thanks!
using UnityEngine;
using System.Collections;
public class DestroyRock : MonoBehaviour
{
public Score score;
void Awake()
{
score = GameObject.FindGameObjectWithTag(“Score”).GetComponent();
}
void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == “Bin1”)
{
Destroy(this.gameObject);
score.Add(1);
}
if (other.gameObject.tag == “Bin2”)
{
Destroy(this.gameObject);
score.Add(1);
}
if (other.gameObject.tag == “Bin3”)
{
Destroy(this.gameObject);
score.Add(1);
}
if (other.gameObject.tag == “Trash”)
{
Destroy(this.gameObject);
score.Add(-1);
}
}
}