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
- How to make a simple ladder? - Unity Answers
- http://☂.net/umbrella/2010/11/unity3d-ladders/
- How to climb up a ladder!! - Unity Answers
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”) ?