void Update() { if (!hasFired) { follow(); } if (Input.GetKey(KeyCode.R)) { target = MissleLauncher.SharedInstance.target; } if (Input.GetKeyUp(KeyCode.R) && target != null) { hasFired = true; transform.parent.SetParent(null, true); } if (hasFired == true) { float distance = Vector3.Distance(transform.position, target.transform.position); if (hasPlayed == false) { launchSound.Play(); thrusterSound.Play(); hasPlayed = true; } ParticleEffect.SetActive(true); lifeTime -= Time.deltaTime; if (lifeTime <= 0) { MissleLauncher.SharedInstance.hasFired = true; Destroy(ParticleEffect); Destroy(transform.parent.gameObject); } if (distance <= detonationThreshold) { MissleLauncher.SharedInstance.hasFired = true; explodeController.gameObject.SetActive(true); explodeController.transform.parent = null; explodeController.Explode(target.transform.position); Destroy(gameObject); } launch(); } }
public void Kill() { if (deathParticles != null) { deathParticles.Play(); deathParticles.transform.parent = null; deathParticleBody.velocity = body.velocity; deathParticleAudioSource.PlayOneShot(deathSound, deathSoundVolume); Destroy(deathParticles.gameObject, deathParticleLifetime); } if (explodeController != null) { explodeController.gameObject.SetActive(true); explodeController.transform.parent = null; explodeController.Explode(AIStaticReferences.RandomPlayerPart.position); } if (doEvolution) { KamikazeEvolver.Instance.AlterStatsByLifeScores(damageDealtToPlayer, Vector3.Distance(player.position, transform.position), angleAccelThreshold, angleAccelThresholdCA, collisionAvoidanceActivationTime); } Destroy(gameObject); }