public class Saglik : MonoBehaviour
{
public float can = 100f; //Can değişkeni
public Vector3 konum;
void Update()
{
konum = transform.position;
}
public void canKaybi(float hasar)
{
can -= hasar;
if (can <= 0f)
{
StartCoroutine(Dirilme(this.gameObject));
}
}
IEnumerator Dirilme(GameObject oyunNesnesi)
{
gameObject.SetActive(false);
yield return new WaitForSeconds(2);
oyunNesnesi.transform.position = new Vector3(1f, 0f, 0f);
oyunNesnesi.SetActive(true); //Oyun nesnesi devrede.
can = 100f; //Can yeniden 100f e yükseltildi.
}
}
Coroutines will not run on deactivated objects. After line 23, the coroutine will simply not continue. The workaround is to simply run the coroutine on a different GameObject, which will not be deactivated.
Thank you so much.I will fix my mistake.