Hi,
Sometimes when the player is on collision with an obstacle, the script is called twice.
public class Collision : MonoBehaviour
{
public Move move;
public Jump jump;
public GameObject player;
public bool check = false;
[SerializeField] private RectTransform replayTxtTrans = null;
[SerializeField] private RectTransform hiscoreTxtTrans = null;
[SerializeField] private RectTransform endGameTxtTrans = null;
void OnCollisionEnter(Collision collisionInfo)
{
if (collisionInfo.gameObject.tag == "Obstacle")
{
move.enabled = false;
jump.enabled = false;
Vibration.VibratePop();
player.GetComponent<Rigidbody>().isKinematic = true;
player.transform.GetChild(1).gameObject.SetActive(false);
player.transform.GetChild(0).gameObject.SetActive(true);
replayTxtTrans.gameObject.SetActive(true);
LeanTween.scale(replayTxtTrans, new Vector3(1f, 1f, 1f), 0.3f).setDelay(0.1f).setEaseInOutBack();
endGameTxtTrans.gameObject.SetActive(true);
hiscoreTxtTrans.gameObject.SetActive(false);
FindObjectOfType<AudioManager>().Play("playerdeath");
check = true;
Debug.Log(check);
}
}
}
In the console he shows this:
Why? Thanks for help.