Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by alijaj · Dec 31, 2015 at 12:35 AM · scripting problemcontrolleranimator controllerinputmanagerhow to

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

37 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges