Hey,
I want my game object to translate only in x axis through accelerometer input,but it is moving in the whole plane …
Can’t figure out why?
Here is C# script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class accelmeter : MonoBehaviour {
// Use this for initialization
public float speed =10f;
Vector3 position;
public float maxpos=2.2f;
void Start () {
position = transform.position;
}
// Update is called once per frame
void Update () {
position.x += Input.acceleration.xspeedTime.deltaTime;
//float z = Input.acceleration.z;
position.x = Mathf.Clamp (position.x, -2.2f, 2.2f);
transform.Translate (tspeedTime.deltaTime,0,0);
//transform.Rotate (0, 0, -zspeedTime.deltaTime);
transform.position = position;
}
}
Please help