- Home /
Question by
IamJarek · Jul 30, 2017 at 12:13 PM ·
componentenable and disable script
Why this script doesn't work? (Disable Component)
Hello, I want to make C# script that will disable walking on "J" key but it doesn't work.
private FirstPersonController FPS; ------ is underlined on red color and FPS = GetComponent<FirstPersonController>(); is underlined too.
using UnityEngine;
using System.Collections;
public class Chodzenie : MonoBehaviour
{
private FirstPersonController FPS;
void Start()
{
FPS = GetComponent<FirstPersonController>();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.J))
{
FPS.enabled = false;
}
}
}
Thank you for help!
Comment
Best Answer
Answer by c4ctus · Jul 30, 2017 at 03:29 PM
The FirstPersonController class belongs to the namespace: "UnityStandardAssets.Characters.FirstPerson"
It allows you to access FirstPersonController:
using UnityStandardAssets.Characters.FirstPerson;
Your answer
![](https://koobas.hobune.stream/wayback/20220612131523im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
"There is no 'GameObject' attached to the "x" game object' 2 Answers
Does a collision occur when a collider 2d is enabled on top of another? 0 Answers
2D Animation does not start 1 Answer
Script.Enabled does not work in Unity 5+ 2 Answers
Speed and efficiency of enabling/disabling component? 1 Answer