I know a little about programing but these are new to me following the 3d buzz vids on making a 2d shooter. Anyway everthing works fine until I add Startcoroutine(Destroyship()) when I save and play the code works once every now and then it will work twice and then I get know collision what so ever. here is the scripts in using c#
// check to see if enemy collides with the player void OnTriggerEnter(Collider otherObject) { if (otherObject.tag == "enemy") { player.Lives--; Enemy enemy = (Enemy)otherObject.gameObject.GetComponent("Enemy"); enemy.setpositionandspeed(); StartCoroutine(Destroyship()); } } //get ship to explode and reappear IEnumerator Destroyship() { Instantiate(explosionprefab, transform.position, Quaternion.identity); gameObject.renderer.enabled = false; transform.position = new Vector3 ( 0f, transform.position.y, transform.position.x); yield return new WaitForSeconds(1.5f); gameObject.renderer.enabled = true; } }
So know one has any Idea? All im trying to do is when my player is killed make him disappear for a second and then reappear at 0 on the x postion. It will work once if I go along time without dying it works twice. then all collision stops seems like it just keeps calling the coroutine and never goes back to the start function. I am at a loss!