Question by
SimonClintonIv · Jun 09, 2016 at 10:09 AM ·
startstopkeypress
How can i disable a function in C#
using UnityEngine;
using System.Collections;
public class PlayerEmptyRotate : MonoBehaviour {
public float horizontalSpeed = 50.0F;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (!Input.GetKey (KeyCode.A) || !Input.GetKey (KeyCode.D) || !Input.GetKey (KeyCode.W) || !Input.GetKey (KeyCode.S))
{
float h = horizontalSpeed * Input.GetAxis ("Mouse X");
transform.Rotate (0, h, 0);
}
}
}
The above is the code where I was trying to start the function in the if statement when those mentioned keys are not pressed and stop when any one of those keys is pressed.
Comment
Best Answer
Answer by sinoby · Jun 09, 2016 at 10:59 AM
just change || to &&
if (!Input.GetKey (KeyCode.A) && !Input.GetKey (KeyCode.D) && !Input.GetKey (KeyCode.W) && !Input.GetKey (KeyCode.S))
Your answer
Follow this Question
Related Questions
Noob: Fresh install play/stop problem 0 Answers
Start a movie texture after another movie texture has ended 0 Answers
Stop the Vehicle Engine / Start Vehicle 0 Answers
Best way to Start/Stop script during runtime. 0 Answers
unity does not start 0 Answers