Hi
I have a collider through which player will lose 1 point. I implemented the functionality but the score is decrementing twice.
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.CompareTag("Player"))
{
FindObjectOfType<Coin>().DecrementScore();
}
}
and this is my Coin class.
public class Coin : MonoBehaviour {
static int score;
// Use this for initialization
void Start () {
score = 0;
}
// Update is called once per frame
void Update () {
}
void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.CompareTag("Player"))
{
score++;
Destroy(gameObject);
}
}
public int getScore(){
return score;
}
public void setScore(int s){
score = s;
}
public void DecrementScore(){
setScore(score-1);
}
}
what could be the possible issue? Please help!