im having a go at the tutorial for the space shooter, and got to creating the image for the player moment, the debug.Log from the SimpleTouchpad shows that it picking up the vector data but player is not moving. the only error i get is a yellow one saying that: Assets/Scripts/SimpleTouchpad.cs(25,17): warning CS0219: The variable `direction’ is assigned but its value is never used
here is the simple touchpad script
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System.Collections;
public class SimpleTouchpad : MonoBehaviour, IPointerDownHandler, IDragHandler, IPointerUpHandler {
private Vector2 origin;
private Vector2 direction;
void Awake()
{
direction = Vector2.zero;
}
public void OnPointerDown(PointerEventData data)
{//set a start point..
origin = data.position;
}
public void OnDrag(PointerEventData data)
{
Vector2 currentPosition = data.position;
Vector2 directionRaw = currentPosition - origin;
Vector2 direction = directionRaw.normalized;
}
public void OnPointerUp(PointerEventData data)
{// reste everthing..
direction = Vector2.zero;
}
public Vector2 GetDirection()
{
return direction;
}
}
and here is the player controller script…
using UnityEngine;
using System.Collections;
[System.Serializable]
public class Boundary{
public float xMin, xMax, zMin, zMax;
}
public class Playercontroller : MonoBehaviour {
public float tilt;
public float fireRate;
public float Speed;
public Boundary boundary;
public GameObject Shot;
public Transform[] ShotSpawns;
public SimpleTouchpad touchPad;
private float nextFire;
private Rigidbody Rigid;
private AudioSource soundClip;
private Quaternion calibrateQuaternion;
// Use this for initialization
void Start () {
Rigid = GetComponent<Rigidbody>();
soundClip = GetComponent<AudioSource>();
CalibrateAccelerometer();
}
void CalibrateAccelerometer()
{
Vector3 accelerationSnapShot = Input.acceleration;
Quaternion rotateQuaternion = Quaternion.FromToRotation(new Vector3(0.0f, 0.0f, -1.0f), accelerationSnapShot);
calibrateQuaternion = Quaternion.Inverse(rotateQuaternion);
}
Vector3 FixAcceleration(Vector3 acceleration)
{
Vector3 fixedacceleration = calibrateQuaternion * acceleration;
return fixedacceleration;
}
void Update()
{
if (Input.GetButtonDown("Fire1") && Time.time > nextFire)
{
nextFire = Time.time + fireRate;
foreach (var ShotSpawn in ShotSpawns)
{
Instantiate(Shot, ShotSpawn.position, ShotSpawn.rotation);
}
soundClip.Play();
}
}
void FixedUpdate () {
// float moveHorazontal = Input.GetAxis("Horizontal"); <<<<<
// float movevertical = Input.GetAxis("Vertical"); <<<<<<<<< Keyboard Controlls
// Vector3 Movement = new Vector3(moveHorazontal, 0.0f, movevertical); <<<
// Vector3 accelerationRaw = Input.acceleration;
// Vector3 acceleration = FixAcceleration(accelerationRaw);
// Vector3 movement = new Vector3(acceleration.x, 0.0f, acceleration.y);
Vector2 direction = touchPad.GetDirection();
Vector3 movement = new Vector3(direction.x, 0.0f, direction.y);
Rigid.velocity = movement * Speed;
Rigid.position = new Vector3(Mathf.Clamp(Rigid.position.x, boundary.xMin, boundary.xMax), 0.0f, Mathf.Clamp(Rigid.position.z, boundary.zMin, boundary.zMax));
Rigid.rotation = Quaternion.Euler(0.0f, 0.0f, Rigid.velocity.x * -tilt);
}
}
i really hope some one can help me as i’ve been stuck looking at this for a day or so thinking it just something really silly i missed