/// <summary> /// Detects if fish is no longer close to another light /// </summary> private void OnLightExit(GameObject lightObject) { LightSource lightSource = lightObject.GetComponentInParent <LightSource>(); if (lightSource) { if (lightSource.CompareTag("Fish")) { if (!ignoreFishOfSameType || lightSource.gameObject.layer != gameObject.layer) { // Inform subclasses that the NPC went out of sight NPCOutOfSight(lightSource.transform); string otherID = lightSource.GetComponent <AbstractFish>().GetID(); RemoveAction(otherID); } } else if (lightSource.CompareTag("Player")) { // Player id = -1 RemoveAction("-1"); } } if (lightObject.CompareTag("Flare")) { // Stop reacting to the flare RemoveAction("-2"); } }
private void OnConsumedLightSource(LightSource consumedLightSource) { // If the player ate a fish if (consumedLightSource.CompareTag("Fish")) { FlashColor(probeColorEatFish, eatFlashDuration); } // If the player collected a pickup (yellow ball) if (consumedLightSource.CompareTag("Pickup")) { FlashColor(probeColorEatPickup, eatFlashDuration); } }
/// <summary> /// Invoked when the player is hit by a light source that is stronger than him /// </summary> protected override void OnKnockback(LightSource enemyLightSource) { // Calculate a knockback force pushing the player away from the enemy fish Vector2 distance = (Transform.position - enemyLightSource.Transform.position); Vector2 knockback = distance.normalized * movementBean.KnockbackForce; Rigidbody.velocity = Vector3.zero; Rigidbody.AddForce(knockback, ForceMode.Impulse); // If the player was hit by a fish if (enemyLightSource.CompareTag("Fish")) { GameObject.Instantiate(movementBean.FishHitParticles, transform.position, Quaternion.Euler(0, 0, 0)); controllerRumble.PlayerHitByFish(); } movementBean.LastTimeHit = Time.time; }
/// <summary> /// Called when the player is hit by a light source that is stronger than him /// </summary> public override void Knockback(LightSource enemyLightSource) { // Calculate a knockback force pushing the player away from the enemy fish Vector2 distance = (Transform.position - enemyLightSource.Transform.position); Vector2 knockback = distance.normalized * knockbackForce; Rigidbody.velocity = Vector3.zero; Rigidbody.AddForce(knockback, ForceMode.Impulse); // If the player was hit by a fish if (enemyLightSource.CompareTag("Fish")) { // Instantiate hit particles GameObject.Instantiate(fishHitParticles, transform.position, Quaternion.Euler(0, 0, 0)); FlashColor(probeColorHit, hitFlashDuration); // Rumble the controller when the player hits a fish. controllerRumble.PlayerHitByFish(); } // The player was just hit lastTimeHit = Time.time; }