Jump problem animation
using UnityEngine; using System.Collections; using UnityStandardAssets.CrossPlatformInput;
public class player : MonoBehaviour { Rigidbody2D mybody; public float speed = 1.5f; public float jump = 0f; bool move; bool goleft; bool canjump = true; public bool isgrounded; public Animator animator; public float jumpheight = 1.5f; public float jumpcount = 0; public bool isFacingRight = true;
// Use this for initialization
void Start()
{
Debug.Log("idledx");
animator = GetComponent<Animator>();
mybody = this.GetComponent<Rigidbody2D>();
animator.SetBool("idle",false );
animator.SetBool("idle2",false );
animator.SetBool("walk",false );
animator.SetBool("walkleft", false);
animator.SetBool("jump", false);
}
void OnCollisionEnter2D(Collision2D coll)
{
if (coll.gameObject.tag == "ground")
{
Debug.Log("ground");
jump = jumpheight;
jumpcount = 0;
}
}
void Flip()
{
isFacingRight = !isFacingRight;
// Vector3 playerScale = transform.localScale;
// playerScale.x = playerScale.x * -1;
// transform.localScale = playerScale;
}
// Update is called once per frame
void Update () {
}
void FixedUpdate()
{
move = CrossPlatformInputManager.GetButton("Right");
if (move)
{
animator.SetBool("jump", false);
animator.SetBool("idle", false);
animator.SetBool("idle2", false);
animator.SetBool("walk", true);
animator.SetBool("walkleft", false);
Debug.Log("walking right");
transform.position += Vector3.right * speed * Time.deltaTime;
}
else
if (Input.anyKey == false)
{
animator.SetBool("idle", true);
animator.SetBool("walk", false);
}
goleft = CrossPlatformInputManager.GetButton("Left");
if (goleft)
{
animator.SetBool("jump", false);
animator.SetBool("idle", false);
animator.SetBool("idle2", false);
animator.SetBool("walk", false);
animator.SetBool("walkleft", true);
Debug.Log("walking left");
transform.position += Vector3.left * speed * Time.deltaTime;
// animator.transform.Rotate(0, 180, 0);
}
else
if (Input.anyKey == false)
{
animator.SetBool("idle2",true);
animator.SetBool("walkleft", false);
}
canjump = CrossPlatformInputManager.GetButton("Jump");
if (canjump && jumpcount == 0)
{
jumpcount = 1;
animator.SetBool("jump", true);
//here the player jumps on the right when is faced on the right
mybody.velocity = Vector3.up * jump;
{
Debug.Log("in air");
// animator.SetBool("jumpsx", true);
animator.SetBool("idle", false);
animator.SetBool("idle2", false);
animator.SetBool("walk", false);
animator.SetBool("walkleft", false);
}
}
else
if (Input.anyKey == false)
{
animator.SetBool("idle", true);
animator.SetBool("jump", false);
}
if (canjump &&jumpcount == 0 )
{
jumpcount = 1;
//itried with left animation jump but it loads the right animation again...
animator.SetBool("jumpsx", true);
mybody.velocity = Vector3.up * jump;
{
Debug.Log("in air");
// animator.SetBool("jumpsx", true);
//animator.SetBool("idle", false);
//animator.SetBool("idle2", false);
//animator.SetBool("walk", false);
//animator.SetBool("walkleft", false);
// animator.SetBool("jump", false);
}
}
else
if (Input.anyKey == false)
{
animator.SetBool("idle2", true);
animator.SetBool("jumpsx", false);
}
}
}
how can i jump on the left if im on the left side, same for right side, i use crossplatform inputs. help me please everything works fine except the jump
Your answer
![](https://koobas.hobune.stream/wayback/20220612054428im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
OnClick change Animator & Sprite Renderer 2 Answers
Edit InputManager.asset via script - Not a repeat question exactly 0 Answers
FPS Controller 1 Answer
Animations Bad Scripting | Controller Script Buggy | Collider Problem | Beginner Here! 0 Answers
Opening a door animated in Cinema4D gazing at it with Google VR 0 Answers