Hello i got a big problem im trying to make for my game Spike System
The problem is on OnTriggerEnter it detect’s two times i can’t figure out why i tried with gameObject.SetActive to disable my player ( becouse after toucing the spikes he dies ) and enabling it on another function but it doesnt help
Pleas someone im stuck for 5-6 hours now … here is the code
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class StatsManager : MonoBehaviour
{
//score sistem
private int PlayerDiamonds = 0;
public Text DiamondScore;
//sistem zivota
private int PlayerLife = 3;
public Text PlayerLives;
void Start()
{
Debug.Log("welcome");
PlayerDiamonds = 0;
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Diamond"))
{
other.gameObject.SetActive(false);
PlayerDiamonds = PlayerDiamonds + 1;
SetScore();
Debug.Log(PlayerDiamonds);
}
if (other.gameObject.CompareTag("Spike"))
{
gameObject.SetActive (false);
if (PlayerLife <= 1)
{
PlayerLife = 3;
Debug.Log("ZIVOTA : " + PlayerLife);
ResetGame();
}
else
{
PlayerLife = PlayerLife - 1;
Debug.Log("ZIVOTA : " + PlayerLife);
ResetGame();
}
}
}
void ResetGame()
{
gameObject.transform.position = new Vector3(0, 0, 0);
gameObject.SetActive(true);
}
void SetScore()
{
DiamondScore.text = "Diamond's : " + PlayerDiamonds.ToString();
}
}
also you see there is a Diamond system i mean an score system it work’s perfectly i add the tag … i set to IsTrigger …
im thinking it’s an unity bug … remeber it’s always called twice pleas help me