HELP!! I don't know how to do the 2Dcharacter jump only once in C#code
I don't know how to set jump , anyone can help me?please!!
using UnityEngine;
using System.Collections;
public class Charectercontrol : MonoBehaviour {
public float maxSpeed = 5f;
bool facingRight = true;
Animator Anim_wait;
public float maxjump = 20f;
Rigidbody2D rigidbody2d;
public bool grounded;
// Use this for initialization
void Start () {
rigidbody2d = GetComponent<Rigidbody2D>();
Anim_wait = GetComponent<Animator>();
}
void FixedUpdate ()
{
float move = Input.GetAxisRaw ("Horizontal");
bool jump = Input.GetKeyDown (KeyCode.UpArrow);
if (move != 0) {
Anim_wait.SetBool ("run", true);
} else {
Anim_wait.SetBool ("run", false);
}
rigidbody2d.velocity = new Vector2 (move * maxSpeed, rigidbody2d.velocity.y);
if (jump) {
// case Anim_wait.SetBool("jump", true):
rigidbody2d.velocity = new Vector2 (rigidbody2d.velocity.x, maxjump);
}
if (move > 0 &&! facingRight)
Flip ();
else if (move < 0 && facingRight)
Flip ();
}
void Update(){
}
void OnGUI(){
GUI.Label(new Rect(0,0,100,30),rigidbody2d.velocity.ToString());
}
// Update is called once per frame
void Flip (){
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
Comment
https://www.youtube.com/watch?v=Xnyb2f6Qqzg
Please watch this full
Your answer
Follow this Question
Related Questions
I can't do jump in my 2D game 1 Answer
Calculate jumptime 0 Answers
2D sidescrolling game. Jumping problems through platforms and platform effector. 0 Answers
Broken Jump Physics 0 Answers