Hello, I’m stuck on one of my last steps to complete a game. I use the accelerometer to roll a ball around & everyhing works fine when I build for Android also on unity remote on an iPhone. But when I build for iPhone my `float accelY;` code in Start and Fixedupdate is not working. What I’m trying to do is get the device start position so the ball moves correctly with the accelerometer. Is there something I have to do in Xcode for this to work?
float speed = 15;
float accelY;
void Start()
{
accelY = Input.acceleration.y;
}
void FixedUpdate()
{
float x = Input.acceleration.x;
float y = Input.acceleration.y - accelY;
Vector2 dir = new Vector2(x, y):
if (dir.sqrMagnitude > 1)
dir.Normalize();
dir *= Time.deltaTime;
transform.Translate(dir * speed, Space.World);
}
↧