/// <summary> /// Stops and clears particles when they all finish. Despawns this object with the pool. /// </summary> private void OnParticleSystemsDead() { if (system != null) { system.stop(); system.clear(); } StartCoroutine(WaitForAudio()); }
/// <summary> /// Initializes the LineRenderer's that are the lasers and /// the muzzle flash emitter pool. /// </summary> protected override void SetupWeapon() { leftLaser = left.gameObject.AddComponent <LineRenderer>(); leftLaser.material = laserMaterial; leftLaser.shadowCastingMode = ShadowCastingMode.Off; leftLaser.receiveShadows = false; leftLaser.alignment = LineAlignment.View; leftLaser.startWidth = thickness; leftLaser.endWidth = thickness; leftLaser.enabled = false; rightLaser = right.gameObject.AddComponent <LineRenderer>(); rightLaser.material = laserMaterial; rightLaser.shadowCastingMode = ShadowCastingMode.Off; rightLaser.receiveShadows = false; rightLaser.alignment = LineAlignment.View; rightLaser.startWidth = thickness; rightLaser.endWidth = thickness; rightLaser.enabled = false; muzzleFlashEmitters = new ParticleSystems[Mathf.FloorToInt(fireRate * 2.5f)]; muzzleFlashIndex = 0; for (int i = 0; i < muzzleFlashEmitters.Length; ++i) { GameObject muzzleFlash = Instantiate(muzzleFlashEmitter, transform); ParticleSystems muzzleFlashSystem = muzzleFlash.GetComponent <ParticleSystems>(); muzzleFlashSystem.stop(); muzzleFlashSystem.clear(); muzzleFlashEmitters[i] = muzzleFlashSystem; } }
/// <summary> /// Initializes the LineRenderer's for the minigun tracers and /// the muzzle flash emitter pool. /// </summary> protected override void SetupWeapon() { foreach (Renderer r in barrelRenderers) { r.material.SetColor("_overheatColor", overheatBarrelColor); r.material.SetFloat("_overheatPercent", 0.0f); } for (int i = 0; i < left.Length; ++i) { InitLineRenderer(left[i]); InitLineRenderer(right[i]); } muzzleFlashEmitters = new ParticleSystems[Mathf.FloorToInt(fireRate * 2.5f)]; muzzleFlashIndex = 0; for (int i = 0; i < muzzleFlashEmitters.Length; ++i) { GameObject muzzleFlash = Instantiate(muzzleFlashEmitter, transform); ParticleSystems muzzleFlashSystem = muzzleFlash.GetComponent <ParticleSystems>(); muzzleFlashSystem.stop(); muzzleFlashSystem.clear(); muzzleFlashEmitters[i] = muzzleFlashSystem; } }
/// <summary> /// Updates the velocity as long as the time warp is active. /// </summary> private IEnumerator TimeWarp() { trailEmitter.play(); while (reference.enemyAttributes.IsTimeWarped) { pRigidbody.velocity = transform.forward * reference.enemyAttributes.projectileSpeeds[ProjectileId]; yield return(null); } trailEmitter.stop(); timeWarpCoroutine = null; }
public void unparentObjects() { Transform targetParent = unparentSelectObjectsToBulletParent ? transform.parent : objectsToUnparentTarget; for (int i = 0; i < objectsToUnparentOnDestroy.Count; i++) { // In the case of DestroyOnParticlesDead, the object may not exist any more. if (objectsToUnparentOnDestroy[i]) { ParticleSystems particleSystems = objectsToUnparentOnDestroy[i].GetComponent <ParticleSystems>(); if (particleSystems) { particleSystems.stop(); particleSystems.setLoop(false); } objectsToUnparentOnDestroy[i].parent = targetParent; } } }
// ... void Update() { // Input. input.x = Input.GetAxis("Horizontal"); input.y = Input.GetAxis("Vertical"); if (Input.GetMouseButton(1)) { input.y += 1.0f; } // Rotate. Vector3 localVelocity = transform.InverseTransformDirection(rigidbody.velocity); if (localVelocity.magnitude < velocityEpsilon) { localVelocity = Vector3.zero; } Quaternion lookRotation = Quaternion.identity; if (localVelocity != Vector3.zero) { lookRotation = Quaternion.LookRotation(localVelocity); } rotationEulerX = Mathf.LerpAngle(rotationEulerX, lookRotation.eulerAngles.x, Time.deltaTime * turnSpeed); reticleScreenPosition = RectTransformUtility.WorldToScreenPoint(reticle.canvas.worldCamera, reticle.transform.position); Vector3 myScreenPosition = Camera.main.WorldToScreenPoint(transform.position); Vector3 direction = reticleScreenPosition - myScreenPosition; float angleToMouseTemp = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg; float angleToMouse = -angleToMouseTemp + 90.0f; rotationEulerY = Mathf.LerpAngle(rotationEulerY, angleToMouse, Time.deltaTime * turnSpeed); // Weapons. if (Input.GetKey(KeyCode.E)) { if (Input.GetMouseButton(0)) { Bullet bullet = weapon.shoot(rigidbody.velocity); if (bullet) { rigidbody.AddForceAtPosition(-weapon.transform.forward * weaponRecoil, weapon.transform.position); GameManager.instance.cameraShake.shake(cameraShakeParams); } } } else if (Input.GetMouseButtonDown(0)) { Bullet bullet = weapon.shoot(rigidbody.velocity, true); if (bullet) { rigidbody.AddForceAtPosition(-weapon.transform.forward * weaponRecoil, weapon.transform.position); GameManager.instance.cameraShake.shake(cameraShakeParams); } } // VFX. if (Input.GetKeyDown(KeyCode.Space)) { blackHole.play(); } if (Input.GetKeyUp(KeyCode.Space)) { blackHole.stop(); } // Thruster VFX. // Forward-backward thrusters. if (input.y > 0.0f) { if (!ps_thruster.isPlaying()) { ps_thruster.play(); } ps_thruster_reverse.stop(); } else if (input.y < 0.0f) { if (!ps_thruster_reverse.isPlaying()) { ps_thruster_reverse.play(); } ps_thruster.stop(); } else { ps_thruster.stop(); ps_thruster_reverse.stop(); } // Side thrusters. float rotationDelta = rotationEulerY - lastRotationEulerY; float rotationDeltaRounded; if (Mathf.Abs(rotationDelta) < rotationDeltaEpsilon) { rotationDeltaRounded = 0.0f; } else { rotationDeltaRounded = rotationDelta; } float rotationEulerTargetZ = MathUtility.remap(-rotationDeltaRounded, -deltaRotationYToRollZRange.x, deltaRotationYToRollZRange.x, -deltaRotationYToRollZRange.y, deltaRotationYToRollZRange.y); //rotationEulerZ = -rotationEulerTargetZ; rotationEulerZ = Mathf.LerpAngle(rotationEulerZ, rotationEulerTargetZ, Time.deltaTime * rollSpeed); if (input.y >= 0.0f) { if (rotationDeltaRounded > 0.0f) { if (!ps_thruster_left.isPlaying()) { ps_thruster_left.play(); } ps_thruster_right.stop(); } else if (rotationDeltaRounded < 0.0f) { if (!ps_thruster_right.isPlaying()) { ps_thruster_right.play(); } ps_thruster_left.stop(); } else { ps_thruster_left.stop(); ps_thruster_right.stop(); } ps_thruster_left_reverse.stop(); ps_thruster_right_reverse.stop(); } else { if (rotationDeltaRounded < 0.0f) { if (!ps_thruster_left_reverse.isPlaying()) { ps_thruster_left_reverse.play(); } ps_thruster_right_reverse.stop(); } else if (rotationDeltaRounded > 0.0f) { if (!ps_thruster_right_reverse.isPlaying()) { ps_thruster_right_reverse.play(); } ps_thruster_left_reverse.stop(); } else { ps_thruster_left_reverse.stop(); ps_thruster_right_reverse.stop(); } ps_thruster_left.stop(); ps_thruster_right.stop(); } }
// ... void Update() { // Face direction of velocity. Quaternion targetRotation = Quaternion.identity; if (rigidbody.velocity != Vector3.zero) { targetRotation = Quaternion.LookRotation(rigidbody.velocity); } // Smooth this rotation a bit. rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * turnSpeed); // VFX. // Thruster VFX. // Forward-backward thrusters. Vector3 localVelocity = transform.InverseTransformDirection(rigidbody.velocity); if (localVelocity.magnitude < velocityEpsilon) { localVelocity = Vector3.zero; } if (localVelocity.z > 0.0f) { if (!ps_thruster.isPlaying()) { ps_thruster.play(); } ps_thruster_reverse.stop(); } else if (localVelocity.z < 0.0f) { if (!ps_thruster_reverse.isPlaying()) { ps_thruster_reverse.play(); } ps_thruster.stop(); } else { ps_thruster.stop(); ps_thruster_reverse.stop(); } // Side thrusters. //float directionOfRotation; //Vector3 directionToPlayer = transform.position - GameManager.instance.player.transform.position; //if (directionToPlayer.x < 0.0f) //{ // directionOfRotation = 1.0f; //} //else //{ // directionOfRotation = -1.0f; //} //if (localVelocity.z >= 0.0f) //{ // if (directionOfRotation > 0.0f) // { // if (!ps_thruster_left.isPlaying()) // { // ps_thruster_left.play(); // } // ps_thruster_right.stop(); // } // else if (directionOfRotation < 0.0f) // { // if (!ps_thruster_right.isPlaying()) // { // ps_thruster_right.play(); // } // ps_thruster_left.stop(); // } // else // { // ps_thruster_left.stop(); // ps_thruster_right.stop(); // } // ps_thruster_left_reverse.stop(); // ps_thruster_right_reverse.stop(); //} //else //{ // if (directionOfRotation < 0.0f) // { // if (!ps_thruster_left_reverse.isPlaying()) // { // ps_thruster_left_reverse.play(); // } // ps_thruster_right_reverse.stop(); // } // else if (directionOfRotation > 0.0f) // { // if (!ps_thruster_right_reverse.isPlaying()) // { // ps_thruster_right_reverse.play(); // } // ps_thruster_left_reverse.stop(); // } // else // { // ps_thruster_left_reverse.stop(); // ps_thruster_right_reverse.stop(); // } // ps_thruster_left.stop(); // ps_thruster_right.stop(); //} }