- Home /
 
Input.GetAxis("Horizontal") problem
Hey I am wondering why I am getting the errors:Cannot implicitly convert type 'float' to 'bool' , and Vector3 is a type, but used like a variable. This version of the script apparently works for JavaScript, but for C# it is not working, and the Documentation on it looks the same as I typed it in.
Here is the code:
 using UnityEngine;
 using System.Collections;
 
 public class player_script : MonoBehaviour {
     int health = 100;
     int speed = 5;
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
 
         if (Input.GetAxis("Horizontal"))
         {
             transform.Translate(Vector3(Input.GetAxis("Horizontal") * speed * Time.deltaTime, 0,0));
 
 
         }
     
     }
 }
 
 
              I fixed one problem, I needed to add new infront of Vector3, I am still confused on the if (Input.GetAxis("Horizontal")) it says I need a cast or something, but the documentation is correct. I am confused. 
Answer by KG3 · May 30, 2013 at 03:46 AM
Hey everyone I figured it out, the Input.GetAxis(stringhere) returns a float so I have to make something like:
if(Input.GetAxis("Horizontal") != 0) { //do something }
and it worked fine.
Answer by bodec · May 30, 2013 at 03:27 AM
this should fix it also if you search the scripting reference for move there a great walk out of a movement script
 transform.TransformDirection(moveDirection);
 
              Your answer
 
             Follow this Question
Related Questions
Movement along with touch of finger 2 Answers
Smooth value in Input System 0 Answers
Input.GetAxis normal behaviour when both axis inputs active? 0 Answers
How to handle Key + Mouse Wheel simultaneously? 1 Answer
Move an object to Input.Touch location 0 Answers