Disabling a script on a game object using C#

Hi all

I am trying to code a way that the mouse and keyboard (code is off the first person controller script) gets disabled when I’m doing functions such as saving/loading and checking character stats. For example when I press c the game will show the player class and player rank and then I want it to disable the first person controller script so nothing else gets shown until I click on the ok button.

I did follow along with the light example in the tutorials and that works perfect however when I’m doing a Component then a GetComponent it’s saying that UnityEngine.Component does not contain a definition for enabled. Also I did try to change the variable in the firstpersoncontroller script to false but for some reason it’s not finding it and both the script and the variable is public. Here’s the code.

using UnityEngine;
using System.Collections;

public class playerstats : MonoBehaviour
{
public static string Class = “None”;
public static string Rank = “None”;
public static string weapon = “None”;
public static string accessory = “None”;
bool characterstats = false;
public string Acknowledge;
bool equipment = false;
bool DisplayDialog = false;
bool Confirmed = false;
public static int gold = 0;
public Component movement;

void Start()

{
movement = GetComponent();
}

void Update ()

{
if (Input.GetKeyUp (KeyCode.C))

{
movement.enabled = !movement.enabled;
characterstats = true;
Confirmed = true;

}

if (Input.GetKeyUp (KeyCode.E))

{
equipment = true;
}
}

void OnGUI()

{
GUI.color = Color.white;
GUILayout.BeginArea (new Rect (0, 0, 300, 300));

if (characterstats == true)

{

GUILayout.Label (“Character Data:”);
GUILayout.Label (“Class:” + " " + Class);
GUILayout.Label (“Rank:” + " " + Rank);

if (GUILayout.Button (Acknowledge [0]))

{
characterstats = false;
Confirmed = false;
}
}

if (equipment == true)

{
GUILayout.Label (“Equipment:”);
GUILayout.Label (“Weapon:” + " " + weapon);
GUILayout.Label (“Accessories:” + " " + accessory);

if (GUILayout.Button (Acknowledge [0]))

{
equipment = false;
}
}

GUILayout.EndArea ();
}
}

I’m still learning C# so I apologize if I don’t get the technical term right but I know what I need is to find the right function that has enabled part of it (like the light function has the enabled in it) but unfortunately I just don’t know which one of those I need to go along with what I’m trying to do.

Also another problem I’m having is that the component on the player is actually called First Person Controller and not FirstPersonController so if I try to space it I also have problems.

Any help on this would certainly be appreciated.

Thanks

Use Code Tags so everyone can read your code correctly, please.

I’m sorry as I’m still new and learning all the technical terms I don’t know what you mean by code tags but pretty much what I’m trying to do is make a way to disable the script that controls player movement and mouse movement.

For example when a player presses c the character stats will show and will continue to show until the ok button is clicked on. Unfortunately the problem I’m having is that the player can still move, open up the save/load/exit and other gui functions while the character stats gui is still showing and that’s a problem.

As I said on my previous post I followed the light example but as the script isn’t part of the light I just can’t do the private Light movement, so if anyone knows what I should replace Light with so it’ll have enabled that’s all I need.

Thanks

This has nothing to do with the actual thread itself, I’m just helping you so you can get actual help.

Step one is to determine where player input is taken (I didn’t even read the script lol) and wrap it in a statement like “if (!DontAcceptInput){ // movement input here }”

And if you need to disable player input, then set “DontAcceptInput” to true (bool variable) and it won’t let them move!

Thank you very much that’s definitely a good start and I appreciate it. I am definitely learning more than when I first started and I don’t mean to sound like a noob or even like I’m just coming here for answers, the problem I’m facing is that the stuff I need to look, I just can’t find doing Yahoo searches or youtube searches so I appreciate all the help I can get.

Google is almighty. No seriously forget yahoo and google search everything, I find that it gets me what I need every time almost.

Edit: disclaimer - I’ve used yahoo mail and other services for more than a decade - just the facts are that Google has the upper hand in search algorithms - not that I dislike yahoo at all haha.