- Home /
Question by
TauCraft · Sep 21, 2017 at 09:24 AM ·
scripting problemcontrollercontrolsblocking
How to block FPSController ?
I currently have a little script like this:
using UnityEngine;
using System.Collections;
using UnityStandardAssets.Characters.FirstPerson;
public class Typing : MonoBehaviour {
void Update () {
if(Input.GetKeyDown(KeyCode.LeftShift)) {
GameObject.Find("Player").GetComponent<FirstPersonController>().enabled = false;
}
}
}
When I try it out, the IsWalking tag of the First Person Controller actually does get disabled while holding LShift, but I still am able to move around freely. Why is that a thing?
Comment
I saw that LShift was already used as the sprint key. I changed it to LControl, but now nothing happens at all.
Best Answer
Answer by TauCraft · Sep 21, 2017 at 02:08 PM
Solved! It was just an issue of actual key-pressed-detection. My code now looks like this:
using UnityEngine;
using System.Collections;
using UnityStandardAssets.CrossPlatformInput;
using UnityStandardAssets.Characters.FirstPerson;
public class Typing : MonoBehaviour {
private FirstPersonController theMover;
private void Start () {
theMover = GameObject.Find ("FPSController").GetComponent<FirstPersonController>();
}
private void Update () {
if(CrossPlatformInputManager.GetAxis("Fire1") > 0) {
theMover.enabled = false;
} else {
theMover.enabled = true;
}
}
}