Unexpected token if

Hi im new in unity and im trying to make an object float in the water and i make a script but gives me an error. This is the code can someone help me? :

var waterlevel : float =4;
var floatheight : float =  2;
var bouyancyCentreOffset : Vector3;
private var forceFactor : float;
private var actionPoint : Vector3;
private var upLift : Vector3;
function Update ()
{
  
  actionPoint = transform.position + transform.TransformDirection(bouyancyCentreOffset);
  forceFactor = if - ((actionPoint.y = waterlevel) / floatHeight);
  
   if (forceFactor > 0f)
  {
  
     upLift = -Physics.gravity * (forceFactor - rigidbody.velocity.y * bounceDamp);
     rigidbody.AddForceAtPosition(upLift, actionpoint);
     
   }
}

Yep you had more than just the one error. The second = on that line should have been a - .
You had various uppercase/lowercase typos, and you had not declared “bounceDamp” or initialized it.

I found the tutorial and checked your script against it, this should be it without the errors :

var waterLevel : float = 4.0;
var floatHeight : float =  2.0;
var bounceDamp : float = 0.05;
var bouyancyCentreOffset : Vector3;

private var forceFactor : float;
private var actionPoint : Vector3;
private var upLift : Vector3;

function Update() {

    actionPoint = transform.position + transform.TransformDirection(bouyancyCentreOffset);
    forceFactor = 1f - ((actionPoint.y - waterLevel) / floatHeight);
    
    if (forceFactor > 0f) {
    
        upLift = -Physics.gravity * (forceFactor - rigidbody.velocity.y * bounceDamp);
        rigidbody.AddForceAtPosition(upLift, actionPoint);
    }
} 

Have fun, it really is a great little script :smiley:

Edit : For completeness for anyone who likes this script, and as it only seems fair to the guy who made it and the tutorial, here is a link to it :