Search Unity

Acceleramter input

Discussion in 'Android' started by apie2546, Oct 19, 2015.

  1. apie2546

    apie2546

    Joined:
    Sep 13, 2015
    Posts:
    14
    Trying to implement accelerameter into my game, can't figure out what to change it to. I initially wanted buttons to move the player left and right in a 2d space but it got too complicated.

    The original code
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Paddle : MonoBehaviour {
    5.  
    6.     public float paddleSpeed = 1f;
    7.  
    8.  
    9.     private Vector3 playerPos = new Vector3 (0, -9.5f, 0);
    10.  
    11.     void Update ()
    12.     {
    13.         float xPos = transform.position.x + (Input.GetAxis("Horizontal") * paddleSpeed);
    14.         playerPos = new Vector3 (Mathf.Clamp (xPos, -8f, 8f), -9.5f, 0f);
    15.         transform.position = playerPos;
    16.  
    17.     }
    18. }
    How would i convert the get axis to input.acceleration? I keep getting errors