Created
December 27, 2018 08:39
-
-
Save eka/4ee3f95a5764881fe8740f32ce6e346d to your computer and use it in GitHub Desktop.
Acceleration example for Unity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class AccelerationControl : MonoBehaviour | |
{ | |
public float Speed = 50f; | |
// Use this for initialization | |
void Start () { | |
} | |
// Update is called once per frame | |
void Update () | |
{ | |
float horAcceleration = Input.acceleration.x; | |
Vector2 translate = Vector2.one; | |
if (horAcceleration > 0) | |
{ | |
translate = Vector2.right; | |
} | |
else | |
{ | |
translate = Vector2.left; | |
} | |
transform.Translate(translate * Speed * Time.deltaTime); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment