Skip to content

Instantly share code, notes, and snippets.

@eka
Created December 27, 2018 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eka/4ee3f95a5764881fe8740f32ce6e346d to your computer and use it in GitHub Desktop.
Save eka/4ee3f95a5764881fe8740f32ce6e346d to your computer and use it in GitHub Desktop.
Acceleration example for Unity
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