Need help fixing code

I wrote this code in the characterMotor because I am trying to change the gravity of the character when touching water. When I tried pressing the play button this error popped up"Assets/Standard Assets/Character Controllers/Sources/Scripts/CharacterMotor.js(577,10): BCE0089: Type ‘CharacterMotor’ already has a definition for ‘OnControllerColliderHit(UnityEngine.ControllerColliderHit)’ "

Here is my code:

     function OnControllerColliderHit(hit:ControllerColliderHit){
     if (hit.gameObject.tag == "water"){
           Debug.Log("you are changing gravity");
        gravity : float = 0;
       }else{
             gravity : float = 10;
            }

}

1 Answer

1

The error is saying there is already a function called "OnControllerColliderHit() inside of the Character Motor script. You cannot have two functions with the same name and the same signature in a script. On my copy of the Character Motor script, the OnControllerColliderHit() is on line 461. You will need to modify the logic inside this already existing OnControllercolliderHit() function, rather than add a second one. Or, since gravity is a public variable, you can add a new script to your character that uses OnControllerColliderHit() and makes the change.