Hello again,
i got a problem with the OnColliderEnter2D, because if my character hits the Ground tagged with “Grass” the function OnCollider2D is not called. This is a problem because now my character only jumps 1 time.
Here is my code:
var moveSpeed = 4f;
// Jump of Player
var jumpHeight : float = 500;
var isJumping : boolean = false;
var nextTimetoJump : float;
function Update () {
Movement ();
}
function Movement () {
if(Input.GetKey (KeyCode.D))
{
transform.Translate(Vector2.right * moveSpeed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.A))
{
transform.Translate(-Vector2.right * moveSpeed * Time.deltaTime);
}
if(Input.GetKeyDown(KeyCode.Space))
{
if(isJumping == false){
rigidbody2D.AddForce(Vector2.up * jumpHeight);
Debug.Log("isJuming");
isJumping = true;
}
}
}
function OnCollisionEnter2D (coll: Collision2D)
{
if(coll.collider.tag == "Gass")
{
isJumping = false;
Debug.Log("NoJumping!");
}
}
I am using the latest version of Unity
I hope somebody is able to help me :s
Greetings GreenTee.