Laman

Unity Phone Accelerometer

In the unity to use accelerometer using script Input.acceleration
 Example Code:
using UnityEngine;
using System.Collections;

public class AccelerometerInput : MonoBehaviour {

 float accX=0,maxSpeed=8;

 void FixedUpdate(){
  float move = Input.acceleration.x;
  rigidbody2D.velocity = new Vector2 (move * maxSpeed, rigidbody2D.velocity.y);
  //transform.Translate(new Vector2(move * maxSpeed * Time.deltaTime,0));
 }
}

No comments:

Post a Comment

Silahkan