using UnityEngine;
using System.Collections;
public class right4 : MonoBehaviour
{
public float speed;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private void OnGUI()
{
if (GUI.RepeatButton(new Rect(500, 200, 50, 50), "→"))
{
float moveHorizontal = Input.GetButton("right4");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, 0.0f);
rigidbody.AddForce (movement * speed * Time.deltaTime);
}
}
}
The error is in the code: float moveHorizontal = Input.GetButton(“right4”); what it is saying is it cannot convert the floating-point number type to a boolean. Input.GetButton() returns a boolean, not a float–Input.GetAxis() returns a float though. This code should work:
using UnityEngine;
using System.Collections;
public class right4 : MonoBehaviour {
public float speed;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private void OnGUI()
{
if (GUI.RepeatButton(new Rect(500, 200, 50, 50), "→"))
{
float moveHorizontal = Input.GetAxis("Horizontal");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, 0.0f);
rigidbody.AddForce (movement * speed * Time.deltaTime);
}
}
}