- Home /
Question by
TheCodingTraceur · May 26, 2014 at 11:26 PM ·
c#errorcontextexists
PlayerStatisticsGUI.cs(Line 27): Error CS0103: The name 'CharTransform' does not exist in the current context (CS0103) (Assembly-CSharp)
I am getting this error while using this code: using UnityEngine; using System.Collections;
public class PlayerStatisticsGUI : MonoBehaviour {
GameObject Char; //Charachter
Camera CharCam; //Charachter's camera
float CharCamFOV; //Field of view of the the charachter's camera
Transform CharTransfrom; //Charachter's coordinates
// Use this for initialization
void Start () {
GameObject Char = GameObject.Find("FPS Player");
Camera CharCam = Camera.current;
float CharCamFOV = CharCam.fieldOfView;
Transform CharTransform = Char.transform;
}
// Update is called once per frame
void OnGUI () {
GUI.TextArea(new Rect(10, 10, 100, 20), "Player Stats:");
GUI.TextArea(new Rect(50, 40, 100, 20), "FOV:" + CharCamFOV);
GUI.TextArea(new Rect(50, 70, 100, 20), "Coordinates:" + CharTransform);
}
}
How would I go about fixing this? What am I doing wrong?
Comment
Answer by meat5000 · May 27, 2014 at 12:00 AM
Transform CharTransfrom
Typo
Then you declare in Start()
Transform CharTransform but as it's declared in Start() its scope is Limited to Start() and can not be accessed from outside the function.
Also, you are redefining it in Start which is not what you want. The global will never get set that way.
Answer by Kiwasi · May 27, 2014 at 12:15 AM
Remove the declarations in Start() as follows:
// Use this for initialization
void Start () {
Char = GameObject.Find("FPS Player");
CharCam = Camera.current;
CharCamFOV = CharCam.fieldOfView;
CharTransform = Char.transform;
}