- Home /
Question by
banana111 · Apr 24, 2016 at 02:22 PM ·
script.disablefps controller
how to disable the fps controller prefeb script
I have a fps controller and all I want to do Is idsable it but when I disabe ti with "fps.SetActive(false);" the script still works and the script is the one I want to disable how can I do that?
Comment
Answer by Quertie · Apr 29, 2016 at 03:11 PM
In the Unity tutorials on disabling components (and the scripting reference) the way to do it is to use the enabled
property. The SetActive()
method is only used for GameObjects.
using UnityEngine;
using System.Collections;
public class Foo : MonoBehaviour
{
public FirstPersonController fps;
public void disableFPS()
{
fps.enabled = false;
}
}
( the enabled property is inhereted from the Behaviour class, and MonoBehaviour derives from Behaviour . )
You also need to import the standard assets.
using UnityStandardAssets.Characters.FirstPerson;
Answer by carlqwe · Apr 29, 2016 at 03:18 PM
use the GetComponent line,
var fpsController : FirstPersonController;
function Start ()
{
fpsController = GetComponent(FirstPersonController);
fpsController.enabled = false; // Will set the fps controller to false on start
}
Your answer
