Please help. I am able to make my marble move for the Mac, Windows, Web Player platforms. However, I cannot get my joystick to work in Android. For instance, my joystick moves around. However, it will not pick up the rigidbody.Addforce for my sphere. Only my joysticks and keyboards.
using UnityEngine;
using System.Collections;
public class PlayerControlNew : MonoBehaviour
{
public float speed;
public float speedArc = 10;
public GameObject moveJoy;
//accelerometer
private Vector3 zeroArc;
private Vector3 curAc;
private float sensH = 10;
private float sensV = 10;
private float smooth = 0.5f;
public Vector3 movement;
public float moveSpeed = 6.0f;
// public Joystick joystickRight;
void Start()
{
// ResetAxes ();
moveJoy = GameObject.Find("LeftJoystick");
}
void FixedUpdate()
{
if (SystemInfo.deviceType == DeviceType.Desktop) {
float moveHorizontal = Input.GetAxisRaw ("Horizontal");
float moveVertical = Input.GetAxisRaw ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0, moveVertical);
rigidbody.AddForce (movement * speed * Time.deltaTime);
} else {
//Android controls
}
}
//
// void ResetAxes()
// {
// zeroArc = Input.acceleration;
// curAc = Vector3.zero;
// }
void Update ()
{
Vector3 forward = Camera.main.transform.TransformDirection (Vector3.forward);
forward.y = 0;
forward = forward.normalized;
Vector3 forwardForce = new Vector3 ();
if (Application.platform == RuntimePlatform.Android) {
float tmpSpeed = moveJoy.GetComponent<LeftJoystick> ().position.y;
forwardForce = forward * tmpSpeed * 1f * moveSpeed;
} else {
forwardForce = forward * Input.GetAxis ("Vertical") * moveSpeed;
}
rigidbody.AddForce (forwardForce);
Vector3 right = Camera.main.transform.TransformDirection (Vector3.right);
right.y = 0;
right = right.normalized;
Vector3 rightForce = new Vector3 ();
if (Application.platform == RuntimePlatform.Android) {
float tmpSpeed = moveJoy.GetComponent<Joystick> ().position.x;
rightForce = right * tmpSpeed * 0.8f * moveSpeed;
} else {
rightForce = right * Input.GetAxis ("Horizontal") * moveSpeed;
}
rigidbody.AddForce (rightForce);
}
}
