I'm somewhat new to Unity, and I'm trying to figure out a way to add different point values to these different birds when you hit them with a rock (don't ask). It was working like this:
Destroy(other.gameObject);
player.GetComponent<PlayerController>().score += 1;
It adds 1 point to the player when a bird is hit, but when I try to detect which bird was being hit, I get this error:
"Property or indexer 'Component.gameObject' cannot be assigned to -- it is read only"
Is there a better way to do this? Please explain to me like I'm a child or else I will probably not understand.
GameObject bird1;
GameObject bird2;
GameObject bird3;
void Start()
{
bird1 = GameObject.Find("Bird1");
bird2 = GameObject.Find("Bird2");
bird3 = GameObject.Find("Bird3");
}
void OnTriggerEnter(Collider other)
{
if(other.gameObject = bird1)
{
Destroy(other.gameObject);
player.GetComponent<PlayerController>().score += 1;
}
else if(other.gameObject = bird2)
{
Destroy(other.gameObject);
player.GetComponent<PlayerController>().score += 2;
}
else if(other.gameObject = bird3)
{
Destroy(other.gameObject);
player.GetComponent<PlayerController>().score += 3;
}
}