Question by
pradeep11dx · Oct 01, 2018 at 07:41 AM ·
androidbuttonphonecrossplatform
Object Left & Right (AxisTouchButton) not moving
hello sir im trying to move left and right (button) by using Standard assets (axistouchbutton) but i can't move my object. any error not showing in my console plz any one help me how can i do it. here is my code
using UnityEngine; using UnityEngine.UI; using UnityStandardAssets.CrossPlatformInput;
public class PlayerMovement : MonoBehaviour {
public Text countText;
float DirX;
// This is a reference to the Rigidbody componenet called "rb"
public Rigidbody rb;
public int count;
public float forwardForce = 2000f;
// We marked this as "Fixed"Update because we
// are using it to mess with physics.
private void Start()
{
count = 0;
SetCountText();
}
void FixedUpdate()
{
// Add a forward force
rb.AddForce(0, 0, forwardForce * Time.deltaTime); //Add a force of 2000 on the z-axis
DirX = CrossPlatformInputManager.GetAxis("Horizontal");
rb.velocity = new Vector2(DirX * 100, 0);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Pick Up"))
{
other.gameObject.SetActive(false);
count = count + 10;
SetCountText();
}
}
void SetCountText()
{
countText.text = "Score: " + count.ToString();
}
}
Comment
Your answer
Follow this Question
Related Questions
Multiple inputs with one finger on Android? 1 Answer
How Do I Add An Audio File To A Button 2 Answers
Allow button to only be pressed once before reloading scene 1 Answer
Share button AR 0 Answers