//respawn object, or destroy it and create the SpawnOnDeath objects public virtual void Death() { if (respawn) { currentHealth = defHealth; dead = false; Rigidbody rigid = GetComponent <Rigidbody>(); currentHealth = defHealth; InstantRespawn = false; rigid.isKinematic = false; if (this.gameObject.tag == "Player") { AnimatorControl.SetBool("KO", false); } //rigid.velocity *= 0; transform.position = respawnPos; //Original spawn location upon initilization(Start of scene). rigid.velocity *= 0; if (rigid) { rigid.isKinematic = false; rigid.velocity *= 0; } } else { Destroy(gameObject); //Q Consider Object pooling. } //player drop item if (tag == "Player") { // Q - Get Animator Controller AnimatorControl = GetComponent <Throwing>().animator; throwing = GetComponent <Throwing>(); if (throwing && throwing.heldObj && throwing.heldObj.tag == "Pickup") { throwing.ThrowPickup(); } RespawnPlayer(); } if (deadSound) { AudioSource.PlayClipAtPoint(deadSound, transform.position); } flashing = false; flashObject.GetComponent <Renderer>().material.color = originalColor; //Respawn GameObject if (spawnOnDeath.Length != 0) { foreach (GameObject obj in spawnOnDeath) { Instantiate(obj, transform.position, Quaternion.Euler(Vector3.zero)); } } }
//respawn object, or destroy it and create the SpawnOnDeath objects void Death() { //player drop item if (tag == "Player") { throwing = GetComponent <Throwing>(); } if (throwing && throwing.heldObj && throwing.heldObj.tag == "Pickup") { throwing.ThrowPickup(); } if (deadSound) { AudioSource.PlayClipAtPoint(deadSound, transform.position); } flashing = false; flashObject.GetComponent <Renderer>().material.color = originalColor; if (respawn) { Rigidbody rigid = GetComponent <Rigidbody> (); if (rigid) { rigid.velocity *= 0; } transform.position = respawnPos; dead = false; currentHealth = defHealth; } else { if (gameObject.tag != "Enemy") { bonus.transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z); Instantiate(bonus); } Destroy(gameObject); } if (spawnOnDeath.Length != 0) { foreach (GameObject obj in spawnOnDeath) { Instantiate(obj, transform.position, Quaternion.Euler(Vector3.zero)); } } }