void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "Shell1" && hitted == false) { lives -= 1; guiDisplay.SetLivesText(); Destroy(other.gameObject); GameObject clone = Instantiate(explosion, this.transform.position, this.transform.rotation) as GameObject; Destroy(clone, 2f); GetComponent <AudioSource>().PlayOneShot(explosionSound); Invoke("RestartPosition", 3f); GetComponent <Rigidbody>().isKinematic = true; tankshooter.enabled = false; hitted = true; GetComponent <Renderer>().enabled = false; } else if (other.gameObject.tag == "Shell2" && hitted == false) { lives -= 1; guiDisplay.SetLivesText(); Destroy(other.gameObject); GameObject clone = Instantiate(explosion, this.transform.position, this.transform.rotation) as GameObject; Destroy(clone, 2f); GetComponent <AudioSource>().PlayOneShot(explosionSound); Invoke("RestartPosition", 3f); GetComponent <Rigidbody>().isKinematic = true; tankshooter.enabled = false; hitted = true; GetComponent <Renderer>().enabled = false; } else if (other.gameObject.tag == "Crate1" || other.gameObject.tag == "Crate2" || other.gameObject.tag == "Spike1" || other.gameObject.tag == "Spike2" || other.gameObject.tag == "TrapSpike" && hitted == false) { lives -= 1; guiDisplay.SetLivesText(); GameObject clone = Instantiate(explosion, this.transform.position, this.transform.rotation) as GameObject; Destroy(clone, 2f); GetComponent <AudioSource>().PlayOneShot(explosionSound); Invoke("RestartPosition", 3f); GetComponent <Rigidbody>().isKinematic = true; tankshooter.enabled = false; hitted = true; GetComponent <Renderer>().enabled = false; } else if (other.gameObject.tag == "Agent") { lives -= 1; guiDisplay.SetLivesText(); GameObject clone = Instantiate(explosion, this.transform.position, this.transform.rotation) as GameObject; Destroy(clone, 2f); GetComponent <AudioSource>().PlayOneShot(explosionSound); GetComponent <Rigidbody>().isKinematic = true; hitted = true; GetComponent <Renderer>().enabled = false; agent.enabled = false; agent.transform.position = new Vector3(AgentPosition.transform.position.x, AgentPosition.transform.position.y, AgentPosition.transform.position.z); agent.enabled = true; Invoke("RestartPosition", 3f); } }
public void Destroy(Collider other) { igrac.lives -= 1; guiDisplay.SetLivesText(); float x = StartPosition.transform.position.x; float y = StartPosition.transform.position.y; float z = StartPosition.transform.position.z; if (igrac.lives == 0) { gameController.GameOver(); } other.transform.position = new Vector3(x, y, z); other.GetComponent <Rigidbody>().velocity = new Vector3(0, 0, 0); other.GetComponent <Rigidbody>().angularVelocity = new Vector3(0, 0, 0); }
void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "Coin1") { GetComponent <AudioSource>().PlayOneShot(coin); igrac.score += 5; guiDisplay.SetScoreText(); Quaternion rotation = new Quaternion(0, 1, 0, 0); GameObject clone = Instantiate(PickUp, other.transform.position, rotation) as GameObject; Destroy(clone, 3); Destroy(other.gameObject); } else if (other.gameObject.tag == "Coin2") { GetComponent <AudioSource>().PlayOneShot(coin); igrac.score += 10; guiDisplay.SetScoreText(); Quaternion rotation = new Quaternion(0, 1, 0, 0); GameObject clone = Instantiate(PickUp, other.transform.position, rotation) as GameObject; Destroy(clone, 3); Destroy(other.gameObject); } else if (other.gameObject.tag == "Life") { GetComponent <AudioSource>().PlayOneShot(life); igrac.lives += 1; guiDisplay.SetLivesText(); Quaternion rotation = new Quaternion(0, 1, 0, 0); GameObject clone = Instantiate(PickUpHeart, other.transform.position, rotation) as GameObject; Destroy(clone, 3); Destroy(other.gameObject); } else if (other.gameObject.tag == "Key") { isCarryingKey = true; Quaternion rotation = new Quaternion(0, 1, 0, 0); GameObject clone = Instantiate(PickUpKey, other.transform.position, rotation) as GameObject; Destroy(clone, 3); Destroy(other.gameObject); } }