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 yusi_bjk · Jan 15, 2019 at 04:28 PM · unity 5unity 2d

I cannot run left and right movement buttons.

my move script :

using System.Collections; using UnityEngine; using UnityStandardAssets.CrossPlatformInput;

public class move : MonoBehaviour {

 private Rigidbody2D rb;
 private float dirX;
 private float moveSpeed = 10f;

 void Start () {
     rb = GetComponent<Rigidbody2D>();

 }

 void Update () {
     dirX = CrossPlatformInputManager.GetAxis ("Horizontal") * moveSpeed;
     rb.velocity = new Vector2 (dirX, 0f);
 }

}

my AxisTouchButton Script : { public class AxisTouchButton : MonoBehaviour, IPointerDownHandler, IPointerUpHandler { // designed to work in a pair with another axis touch button // (typically with one having -1 and one having 1 axisValues) public string axisName = "Horizontal"; // The name of the axis public float axisValue = 1; // The axis that the value has public float responseSpeed = 3; // The speed at which the axis touch button responds public float returnToCentreSpeed = 3; // The speed at which the button will return to its centre

     AxisTouchButton m_PairedWith; // Which button this one is paired with
     CrossPlatformInputManager.VirtualAxis m_Axis; // A reference to the virtual axis as it is in the cross platform input

     void OnEnable()
     {
         if (!CrossPlatformInputManager.AxisExists(axisName))
         {
             // if the axis doesnt exist create a new one in cross platform input
             m_Axis = new CrossPlatformInputManager.VirtualAxis(axisName);
             CrossPlatformInputManager.RegisterVirtualAxis(m_Axis);
         }
         else
         {
             m_Axis = CrossPlatformInputManager.VirtualAxisReference(axisName);
         }
         FindPairedButton();
     }

     void FindPairedButton()
     {
         // find the other button witch which this button should be paired
         // (it should have the same axisName)
         var otherAxisButtons = FindObjectsOfType(typeof(AxisTouchButton)) as AxisTouchButton[];

         if (otherAxisButtons != null)
         {
             for (int i = 0; i < otherAxisButtons.Length; i++)
             {
                 if (otherAxisButtons[i].axisName == axisName && otherAxisButtons[i] != this)
                 {
                     m_PairedWith = otherAxisButtons[i];
                 }
             }
         }
     }

     void OnDisable()
     {
         // The object is disabled so remove it from the cross platform input system
         m_Axis.Remove();
     }


     public void OnPointerDown(PointerEventData data)
     {
         if (m_PairedWith == null)
         {
             FindPairedButton();
         }
         // update the axis and record that the button has been pressed this frame
         m_Axis.Update(Mathf.MoveTowards(m_Axis.GetValue, axisValue, responseSpeed * Time.deltaTime));
     }


     public void OnPointerUp(PointerEventData data)
     {
         m_Axis.Update(Mathf.MoveTowards(m_Axis.GetValue, 0, responseSpeed * Time.deltaTime));
     }
 }

}

alt text

sorun-1.png (251.8 kB)
sorun-2.png (173.0 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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by tormentoarmagedoom · Jan 15, 2019 at 04:42 PM

Good day.

Thats not the way @yusi_bjk .... Post something, and we will try to help you to see where is the problem, and how to solve it. But dont expect that we will write a script for you, thats your job, its your project..

PD: We can no write a script to you because we dont knwo what yuo need? what speed= 1, 10 or 1000? What dimnensions 2 or 3? what planes? X and Y, X and Z , X and Z ? Are you doing a mobile app or game app? Mouse? Keyboard?. And sooo many other questions.....

Comment
Add comment · Show 3 · 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 yusi_bjk · Jan 15, 2019 at 05:06 PM 0
Share

edit did and fixed my problem as above

avatar image yusi_bjk · Jan 15, 2019 at 05:07 PM 0
Share

@tormentoarmagedoom plase help bro

avatar image casaldejovesqueix yusi_bjk · Jan 19, 2019 at 10:38 AM 0
Share

Edit your post, use The code sampler to post code, so everybody can easy read it.. Not its like a text book..

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

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

Getting trouble in migrating the Unity IAP old version to new version of IAP in existing project 0 Answers

Unity Shader Optimization? 0 Answers

How to make fast a coroutine 1 Answer

Instantiating A group of platform and moving them down 0 Answers

CommandInvokationFailure: Unable to merge android manifests. ,Unable to merge android manifest Error 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