• 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 /
avatar image
0
Question by vanjasretenovic123 · Aug 26, 2017 at 10:58 AM · androidunity 5inputbuttonjump

How do I make my player jump on click on the button?

alt textHelp me to create jumping script for button. I'm making android inputs, so I need jump button! I found some codes, but it doesn't work. Thank you in advance!

buttoninputq.png (327.8 kB)
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

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by sachinbirajdar · Aug 26, 2017 at 12:16 PM

When the Jump button is triggered try adding some force in y direction to your player.This code should help. Customize it according to your needs.

public float force; public Rigidbody player;

 void Start()
 {
     player= GetComponent<Rigidbody>();
 }

 void FixedUpdate()
 {
     if (CrossPlatformInputManager.GetButton ("Jump"))
     

         {
                   player.AddForce(transform.up * force);
                        }

     
 }

Comment
Add comment · Show 1 · Share
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
avatar image vanjasretenovic123 · Aug 26, 2017 at 02:10 PM 0
Share

Thank you so much, this is work with space. How can I use button ins$$anonymous$$d of SPACE?

avatar image
0

Answer by PersianKiller · Aug 26, 2017 at 05:24 PM

It worked for me ,hope will help you too.

I created a script like this

                           public class touch : MonoBehaviour {


                                        public PlayerController player;
                                     void Start(){
                                       player = FindObjectOfType<PlayerController> ();

// I worte jumping scripts in PlayerController .and with player I can access it.

                                              }

                    public void jump(){
     player.Jump = true;
     
 }

then go to unity and attach the script to the canvas or to the button.then click on your button .

and you can see what to do in the image :)

alt text

so when you click on the button Jump function of PlayerController will do jumping stuffs. :)


untitled.png (25.1 kB)
Comment
Add comment · Show 1 · Share
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
avatar image
0

Answer by vanjasretenovic123 · Aug 26, 2017 at 09:41 PM

I made this script and I did what you said, but it does not work again. alt text

alt text


input.png (17.8 kB)
inputedit.png (154.7 kB)
Comment
Add comment · Show 2 · Share
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
avatar image PersianKiller · Aug 27, 2017 at 04:14 AM 0
Share

it's all you need ,

           //this code is for canvas  or button

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Button : $$anonymous$$onoBehaviour {

 public playerController player;
 // Use this for initialization
 void Start () {
     player = FindObjectOfType<playerController> ();
 }
 
 // Update is called once per frame
 void Update () {
     
 }

 public void makePlayerJump(){
 //    player = FindObjectOfType<playerController> ();
     player.jump ();


 }

}


      and it's for your player or whatever that you want to make it jump



using System.Collections; using System.Collections.Generic; using UnityEngine;

public class playerController : $$anonymous$$onoBehaviour {

   Rigidbody2D rig;
 public float jumpHeight;
 // Use this for initialization
 void Start () {
     rig = GetComponent<Rigidbody2D> ();
 }

 public void jump(){

     rig.velocity = new Vector2 (0,jumpHeight);
     //or you can use addforce
 }



}


avatar image PersianKiller · Aug 27, 2017 at 04:40 AM 0
Share

watch this it will help you :) https://www.youtube.com/watch?v=6WCXhQOukFQ&feature=youtu.be

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

213 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 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 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 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 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 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

Android performance hit on changing Button.Interactable 1 Answer

best way to handle input on a 2D map button 1 Answer

Input lag on Andorid but not in Unity 1 Answer

GUI button doesn't appear on Android 0 Answers

Android input only works with remote 1 Answer


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