I am trying to make an object, that when told starts falling, and after a designated length of time respawns where it was before, but for some reason, my rigidbody and collider are not re-enabling, here is my code:
public float respawnDelay;
public float WaitTime;
public GameObject ground;
public Rigidbody2D rb;
public Collider2D goingThroughObjects;
private Vector3 whereToTeleport;
// Use this for initialization
void Start ()
{
rb = GetComponent<Rigidbody2D>();
goingThroughObjects = GetComponent<Collider2D>();
rb.isKinematic = true;
goingThroughObjects.enabled = true;
}
// Update is called once per frame
void Update ()
{
}
void OnTriggerEnter2D(Collider2D other)
{
if(other.tag == "HeadStomp")
{
StartCoroutine("TouchedBreakableObjectCo");
}
}
public IEnumerator TouchedBreakableObjectCo()
{
whereToTeleport = ground.transform.position;
yield return new WaitForSeconds(WaitTime);
rb.isKinematic = false;
yield return new WaitForSeconds(0.2f);
goingThroughObjects.enabled = false;
yield return new WaitForSeconds(respawnDelay);
rb.isKinematic = true;
goingThroughObjects.enabled = true;
ground.transform.position = whereToTeleport;
}
PLEASE HELP