public void Collect() { collected = true; velocity = velocityMax; GetComponent <CapsuleCollider>().enabled = false; if (collectSound != null) { SoundEffectScript.PlaySoundEffect(transform.position, collectSound); } }
// Handle a hit to the killable object (only if it can currently be hit) public void Hit(int power) { // Cancel the whole function if the object can't be hit or the killablescript isn't active if (!canBeHit || !alive) { return; } // Disable hits to the object for a short time canBeHit = false; // If power requirement met, do damage based on attack power level (and power requirement functions as armor) if (power >= powerRequirement && health > 0) { health -= (power - (powerRequirement - 1)); } // Handle death or recovery if (health <= 0) { // Kill the killable object (with fancy particle effects provided by the generator) alive = false; if (polyParticleGenerator != null) { GameObject particleFX = Instantiate(polyParticleGenerator); particleFX.transform.position = transform.position; particleFX.transform.rotation = transform.rotation; } // Play the death sound if (deathSound != null) { SoundEffectScript.PlaySoundEffect(transform.position, deathSound); } // If preserve isn't set, destroy the object completely if (!preserveAfterDeath) { Destroy(gameObject); } } else { // Not dead yet, so start recovery StartCoroutine(HitRecover()); // Play the hit sound if (hitSound != null) { SoundEffectScript.PlaySoundEffect(transform.position, hitSound); } } }
/// <summary> /// Kill the player with a death sound and a small splash of pixel blood /// </summary> public void Kill() { // TODO - visual death effects // Death sound effect if (deathSound != null) { SoundEffectScript.PlaySoundEffect(transform.position, deathSound); } // Make a pixel blood splash effect for a dramatic death ParticleEffectScript.Splash(bloodParticlePrefab, transform, 25, 0.1f, 75.0f, 75.0f, 300.0f); // TODO - respawn player and reset level }
// Called at a fixed rate along with physics updates private void FixedUpdate() { // Jump movement if (Input.GetButtonDown("Jump") && grounded) { // TODO - apply jump movement if (jumpSound != null) { SoundEffectScript.PlaySoundEffect(transform.position, jumpSound); // Jumping sound effect } } // Horizontal movement moveVelocity.x += Input.GetAxis("Horizontal"); moveVelocity.x = Mathf.Clamp(moveVelocity.x, -speed, speed); // TODO - better movement // Set the animator parameters GetComponent <Animator>().SetBool("Grounded", grounded); GetComponent <Animator>().SetFloat("HVelocity", moveVelocity.x / speed); GetComponent <Animator>().SetFloat("VVelocity", moveVelocity.y / speed); }