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 /
This question was closed May 02, 2016 at 12:34 AM by Miggarapo for the following reason:

Problem is not reproducible or outdated

avatar image
0
Question by Miggarapo · Jan 21, 2016 at 03:25 PM · movementbuttonplayer

Move Player (y-Axis) on click button does not work

ButtonMovement SCRIPT:

using UnityEngine; using System.Collections;

public class ButtonMovement : TouchManager { public bool moveRight = false; public float moveSpeed = 5.0f; public GameObject player = null;

 // Use this for initialization
 void Start () {
 
 }
 
 // Update is called once per frame
 void Update () {
     TouchInput();
 }

 void OnFirstTouch()
 {
     if (moveRight)
     {
         player.transform.Translate (Vector2.right * moveSpeed * Time.deltaTime);
     }
     else if (!moveRight)
     {
         player.transform.Translate (-Vector2.right * moveSpeed * Time.deltaTime);
     }
 }
 void OnSecondTouch()
 {
     if (moveRight)
     {
         player.transform.Translate(Vector2.right * moveSpeed * Time.deltaTime);
     }
     else if (!moveRight)
     {
         player.transform.Translate(-Vector2.right * moveSpeed * Time.deltaTime);
     }
 }

}

TouchManager SCRIPT:

using UnityEngine; using System.Collections;

public class TouchManager : MonoBehaviour { public static bool guiTouch = false;

 public void TouchInput ()
 {
     //GUI TEXTURES ONLY
     if(GetComponent<GUITexture>() != null)
     {
         if (GetComponent<GUITexture>().HitTest(Input.GetTouch(0).position))//0=first touch
         {
             guiTouch = true;

             switch (Input.GetTouch(0).phase)
             {
                 case TouchPhase.Began:
                     SendMessage("OnFirstTouchBegan");
                     SendMessage("OnFirstTouch");
                     break;
                 case TouchPhase.Moved:
                     SendMessage("OnFirstTouchMoved");
                     SendMessage("OnFirstTouch");
                     break;
                 case TouchPhase.Stationary:
                     SendMessage("OnFirstTouchStationary");
                     SendMessage("OnFirstTouch");
                     break;
                 case TouchPhase.Ended:
                     SendMessage("OnFirstTouchEnded");
                     SendMessage("OnFirstTouch");
                     guiTouch = false;
                     break;
             }
         }
         if (GetComponent<GUITexture>().HitTest(Input.GetTouch(1).position))//1=second touch
         {
             guiTouch = true;

             switch (Input.GetTouch(1).phase)
             {
                 case TouchPhase.Began:
                     SendMessage("OnSecondTouchBegan");
                     SendMessage("OnSecondTouch");
                     break;
                 case TouchPhase.Moved:
                     SendMessage("OnSecondTouchMoved");
                     SendMessage("OnSecondTouch");
                     break;
                 case TouchPhase.Stationary:
                     SendMessage("OnSecondTouchStationary");
                     SendMessage("OnSecondTouch");
                     break;
                 case TouchPhase.Ended:
                     SendMessage("OnSecondTouchEnded");
                     SendMessage("OnSecondTouch");
                     guiTouch = false;
                     break;
             }
         }
     }
 }

}

I have a 2d rigidbody Player which is falling on the ground. Both got box collider 2d. I add ButtonMovement to button left and button right and checked the move right [x] on button right. I added my Player to both scripts in my Buttons.

By pressing those Buttons, nothing happens. Any help? Its an Android app!

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

  • Sort: 

Follow this Question

Answers Answers and Comments

42 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

Related Questions

Mobile Left and right move input for the player in 2D (Top Down) 0 Answers

[Help] Player stops moving when hitting wall diagonally 0 Answers

Hit a wall in my RTS movement controller. Issues with MoveToward and Coroutine logic. 0 Answers

Navmesh based player movement 1 Answer

Move an sphere when button clicked 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