Question by
huseyinbaba58 · Aug 03, 2020 at 03:19 PM ·
unity5
How to reach StartCoroutine() non active game object ?
I want to create respawn system .But I am failed.When I had run game,game object prefab was getting passive.But I want to game object be active after when game object was passive. I moved script code to inside of StartCoroutine().
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.
}
}
Comment