I have an underwater slow effect in place whenever my character goes under water.
Here is the code for that:`using UnityEngine;
using System.Collections;
public class WaterPhysics : MonoBehaviour
{
//CapsuleCollider UnderWater;
// Use this for initialization
Animation _animation;
void Start ()
{
_animation = GetComponentInChildren ();
//UnderWater = GetComponent ();
}
private void OnTriggerStay (Collider Submerge)
{
GameObject thePlayer = GameObject.FindGameObjectWithTag ("Player");
PlayerMovement PlayerMovement1 = thePlayer.GetComponent ();
if (Submerge.tag != "Water1") {
_animation ["RunForward"].speed = 1;
_animation ["RunBackward"].speed = 1;
_animation ["RunRight"].speed = 1;
_animation ["RunLeft"].speed = 1;
PlayerMovement1._gravity = 2;
PlayerMovement1._moveSpeed = 25;
} else if (Submerge.tag == "Water1") {
//Debug.Log ("we Are underwater!");
_animation ["RunForward"].speed = 0.5f;
_animation ["RunBackward"].speed = 0.5f;
_animation ["RunRight"].speed = 0.5f;
_animation ["RunLeft"].speed = 0.5f;
PlayerMovement1._gravity = 1.0f;
PlayerMovement1._moveSpeed = 5.0f;
}
}
}
`
It works properly until I my Raptor game object which follows me, gets close. It has it's own boxcollider that I have set so it can switch animations from walk to sprint once I get close enough to it.
The problem is, while under water, I think that once the raptor gets in range, the script picks up his tag or boxcollider rather than the waters tag or box collider and lets my character run at full speed because the Submerge.tag != "Water1" any more because it equals the raptor's tag even though I am still underwater.
I would like some help if there is a way to make the water code ignore the raptor but I still have the effect of the raptor sprinting at me when in range.
↧