A simple ladder in C# or Js

Hi all !

I’m very new (and bad) at scripting and i’ve a ladder to realize for a project we’re doing with friends of mine.
I’ve a third person character based on the “Mecanim tutorial for Unity 4.0” = Unity 4.0 - Mecanim Animation Tutorial - YouTube that is a prefab and has a C# script used to move it.

I’ve tried to make a simple ladder script (touch a collider, climb the ladder,…, profit !) but all i have when i’m entering the collider is… no response.

I’ve used the following solution

But none of them seems to work for me

The latest code i’m trying to use is this one (attached to the ladder)

var playerObject : GameObject;
var canClimb = false;
var speed : float = 1;
     
function Start () {
	
	playerObject = gameObject.Find("Cesareredim 1");
   }
     
function OnTriggerEnter (collider : Collision){
	
	if(collider.gameObject == playerObject){
    	
    	canClimb = true;
            playerObject.rigidbody.useGravity = false;
    	
    	}
    }
     
function OnTriggerExit (collider : Collision){
    
    if(collider.gameObject == playerObject){
    	canClimb = false;
            playerObject.rigidbody.useGravity = true;
    
    	}
    }
    
function Update () {
    
    if(canClimb == true){
    
    	
    	
    	if(Input.GetKey(KeyCode.Z)){
    		
    		playerObject.transform.Translate (Vector3(0,1,0) * Time.deltaTime*speed);
    
    }
    	if(Input.GetKey(KeyCode.S)){
    		
    		playerObject.transform.Translate (Vector3(0,-1,0) * Time.deltaTime*speed);
    	
    	
    	
    	}
    }
}

My first question is : Did the mix of C# for my character and Javascript for the ladder work properly ?
My second question is : Is it possible to create a simple function for climbing in C# that i didn’t know (using a key when entering the collider of an object with a tag “Ladder”) ?

Okay !!! I FINALLY did it !

All i have to add was

function OnTriggerEnter (collider : Collision){
 
if(**other**.collider.gameObject == playerObject){
 
canClimb = true;
 
}

}
 
function OnTriggerExit (collider : Collision){
 
if(**other**.collider.gameObject == playerObject){
canClimb = false;
 
}

}

So i hope this will help many in the future !

Your problem might be in your collider function:

function OnTriggerExit (collider : Collision){
 
    if(collider.gameObject == playerObject){
        canClimb = false;
 
        }
    }

Is ‘playerObject’ a name? or a tag? Try:

if(collider.gameObject.name == "playerObject");

Or

if(collider.gameObject.tag == "playerObject");

here is a video on making a ladder hope it helps Unity Tutorial Ladders With Free Script Included Unity 5 supported - YouTube