Question by
Allin1gamer · Mar 06, 2017 at 06:13 PM ·
rigidbodycuberoll
How can i make the cube roll
How can i make the cube roll(like in real life) when I tilt the screen using UnityEngine; using System.Collections;
public class Player : MonoBehaviour {
private float speed = 15f;
public float mapWidth = 2f;
private Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
Vector3 dir = Vector3.zero;
dir.x = -Input.acceleration.y;
if (dir.sqrMagnitude > 1)
dir.Normalize();
dir *= Time.deltaTime;
transform.Translate(dir * speed);
}
void OnCollisionEnter()
{
FindObjectOfType<GameManager>().EndGame();
}
}
Comment