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