Question by 
               miteshchakma · Dec 19, 2015 at 09:20 PM · 
                movement scriptmove an object  
              
 
              input.getaxis returning -1 by default
using UnityEngine; using System.Collections;
public class Player : MonoBehaviour {
 public float speed = 8.0f;
 public float maxVelocity =3.0f;
 // Use this for initialization
 void Start () {
 }
 // Update is called once per frame
 void Update () {
     float force = 0.0f;
     float velocity = Mathf.Abs (GetComponent<Rigidbody2D>().velocity.x);
     float h = Input.GetAxis ("Horizontal"); //getting input along x-axis only
     Debug.Log (h);
         if (h > 0) {
             if (velocity < maxVelocity) {
                 force = speed;
             }
             Vector3 scale = transform.localScale;
             scale.x = 1;
             transform.localScale = scale;
         } else if (h < 0) {
             if (velocity < maxVelocity) {
                 force = -speed;
             }
             Vector3 scale = transform.localScale;
             scale.x = -1;
             transform.localScale = scale;
         }
         GetComponent<Rigidbody2D>().AddForce (new Vector2 (force, 0));
 }
 
               }
               Comment
              
 
               
              Is it logging -1 every frame?
Try unplugging any joysticks. Perhaps you have a joystick tucked away somewhere where something is pushing the stick.
yap it is logging -1 every frame .
I did not attached any joysticks, it is giving -1 by default
Your answer
 
             Follow this Question
Related Questions
SImple, but how do I check a game object's position in an If statement? 1 Answer
how do i fix the compiler errors on unity 5? i have tried everything there is to try. 0 Answers
Y-axis movement stuck. Help me please :c,Not Moving by pressing Button :C. Help me please 0 Answers
Object Manipulation and a foreign object 0 Answers
Move gameobject when clicking on another gameobject 1 Answer