What's wrong with this script?

function NoGravity(){
rigidbody.useGravity = false;
}

function Gravity(){
transform.Translate(Vector3.up * 1 * Time.time);
rigidbody.useGravity = true;
}

function OnTriggerEnter (Water : Collider) {
if (Water.gameObject.CompareTag (“Water”)) {
var Collider = GameObject.Find(“Water”);
NoGravity();
}
}

function OnTriggerExit (Water : Collider) {
if (Water.gameObject.CompareTag (“Water”)) {
var Collider = GameObject.Find(“Water”);
Gravity();
}
}

I have it attached to a “thing” that is set to follow the main character so when it falls in the “Water” trigger area, it’s rigidbody won’t use gravity, so it can seem to swim. I have it set to translate up some when it exits the water box so it will first “jump” out before having gravity pull it back down.

Ummm No offence but I’d just try a new script. Unity is built with a physics engine that could handle this and make it look good. Translation isn’t great for physics sims. Try

var upForce : float;
function OnTriggerStay (water : Collider)
{
if(water.tag == water) //Or use anyway of figuring it out it’s the right object like using layers
rigidbody.AddForce(Vector3.up * upForce);
//Then you’re object after you put a rigidbody in will go up when it hits the water and still be affected by gravity. It looks much nicer
}

I can’t seem to get detection of the water to occur. I was very hopeful about layers working, I’ve been able to use layers to cause other behaviors but not in this case. Does the “water” collider need to have any special attributes like being a trigger or having(or not having) a rigidbody(kinematic?) attached when using the OnTriggerStay call?

Ok yes the water NEEDS to be a Trigger for onTriggerStay and it needs to have a kinematic rigidbody. Don’t worry I was confused for maybe an hour trying to get the detection to work because I forgot a rigidbody XD

I think I may have one those deep issues where something in another script is effecting something else because even with a kinematic rigidbody there’s no “swimming”. I’m going to move on with other aspects of the game for now and hopefully the answer will reveal itself sooner or later. Thanks for trying.