Object Tagging Trouble

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);
}

}
}

Make sure to use code tags for easier to read posts:

If you don’t think the tags are working you could add a line like this to the if statement’s:

if (other.gameObject.tag == "Bin3")
{
   Debug.Log("Fell into Bin3.  Adding 1");
   Destroy(this.gameObject);
   score.Add(1);
}

What does the Score class look like? What is your error exactly. Do you display the score somewhere and its not updating? If so, it could be your code to display the score isn’t working correctly even if the score itself is. Have you debugged the Add function to see if the score is being properly added to?