Disable movement button, C#
Hi.
I need to disable just movement backward. I mean when I press "down" character must do nothing. I have no idea what I need to do.
There is my script:
using UnityEngine; using System.Collections;
public class Player : MonoBehaviour {
private Animator anim;
private CharacterController controller;
public float speed = 6.0f;
public float turnSpeed = 0.0f;
private Vector3 moveDirection = Vector3.zero;
public float gravity = 20.0f;
// Use this for initialization
void Start () {
anim = gameObject.GetComponentInChildren<Animator> ();
controller = GetComponent<CharacterController> ();
}
// Update is called once per frame
void Update () {
if (Input.GetKey ("up")) {
anim.SetInteger ("AnimPar", 1);
} else {
anim.SetInteger ("AnimPar", 0);
}
{
if (Input.GetKey ("down")) {
\\ here probably a solution
}
if (controller.isGrounded) {
moveDirection = transform.forward * Input.GetAxis("Vertical") * speed;
}
float turn = Input.GetAxis ("Horizontal");
transform.Rotate (0, turn * turnSpeed * Time.deltaTime, 0);
controller.Move (moveDirection * Time.deltaTime);
moveDirection.y -= gravity * Time.deltaTime;
}
}
Answer by TBruce · Oct 02, 2016 at 08:26 PM
The easiest solution would be to do this
Go to "Edit\Project Settings\Input" from the main menu
Select the Axes drop down in the inspector
Clear the "Negative Button" and "Alt Negative Button" values (defaults are
down
ands
)
Now Unity will ignore both buttons.
Your answer
Follow this Question
Related Questions
Input.GetAxisRaw always returns -0.6 1 Answer
GoogleVR / C# - How to, with the "pointer click": click 1 move a cube and click 2 move back the cube 0 Answers
Unity 2D: player character speeds up unintantionally 3 Answers
SImple, but how do I check a game object's position in an If statement? 1 Answer