When there is two coin clones in the same position and my player goes on top of them, I want it to only add to my coins value by 1 but it does it by how many coins are in the same position. Any help?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Coin : MonoBehaviour
{
[SerializeField]
private PlayerController player;
private bool collectCoin;
void Start()
{
player = GameObject.Find("Player").GetComponent<PlayerController>();
}
private void OnTriggerEnter(Collider other) {
if (other.CompareTag("Player") && collectCoin == false) {
collectCoin = true;
player.coins++;
collectCoin = false;
Destroy(this.gameObject);
}
//one clone colliding with the other ones in the same position and destroying each other
if (other.transform.position == gameObject.transform.position) {
Destroy(other.gameObject);
Destroy(this.gameObject);
}
}
}