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
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.....
Edit your post, use The code sampler to post code, so everybody can easy read it.. Not its like a text book..
Your answer
Follow this Question
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