- Home /
does not exist in the current context error
Hello,
I am having trouble finding advanced player in this c# script
void OnGUI () {
AdvancedPlayer = GameObject.Find("AdvancedPlayer");
vp_FPPlayerEventHandler Player = AdvancedPlayer.transform.root.GetComponentInChildren();
}
Thanks, Joseph
Is the AdvancedPlayer variable of the type Gameobject? If not and also if you don't declare the AdvancedPlayer variable anywhere you should do:
Gameobject AdvancedPlayer = Gameobject.Find("A......
Also you should avoid gameobject.find in OnGUI and Update functions. You should assign the variable only once (for example in Start() or using the Component Inspector) because what you're trying to do there can cause massive performance-issues. Also the Component-Array you are trying to assign there should be assigned only once.
$$anonymous$$ake sure that you really have a gameobject with the name AdvancedPlayer. Also I would recommend you to maybe use tags ins$$anonymous$$d of names to find a gameoject.
if this helps here is my current script:
using UnityEngine;
using System.Collections;
public class Questing : $$anonymous$$onoBehaviour {
private float x;
private float y;
private GameObject AdvancedPlayer;
private Vector2 resolution;
public int quest = 0;
// Use this for initialization
void Start () {
GameObject AdvancedPlayer = GameObject.Find("AdvancedPlayer");
resolution = new Vector2(Screen.width, Screen.height);
x=Screen.width/1920.0f; // 1920 is the x value of the working resolution (as described in the first point)
y=Screen.height/1080.0f; // 1042 is the y value of the working resolution (as described in the first point)
}
// Update is called once per frame
void Update () {
if(Screen.width!=resolution.x || Screen.height!=resolution.y)
{
resolution=new Vector2(Screen.width, Screen.height);
x=resolution.x/1920.0f;
y=resolution.y/1080.0f;
}
}
void OnGUI () {
vp_FPPlayerEventHandler Player = AdvancedPlayer.transform.root.GetComponentInChildren<vp_FPPlayerEventHandler>();
if(quest == 1){
GUI.Box(new Rect(500*x,20*y,100*x,50*y), "Quests");
GUI.Button(new Rect(500*x,40*y,100*x,50*y), "Here! take this mace to start questing! - Reward = $$anonymous$$ace");
Player.SetWeapon.TryStart(1);
}
}
void OnTriggerEnter (Collider other) {
quest = 1;
}
void OnTriggerExit (Collider other) {
quest = 0;
}
}
What is not working correctoly? are you getting any errors? Please give us more detail about your issue.
Answer by techisbest13 · Jun 18, 2018 at 05:25 PM
I think what you need to do is add GameObject to AdvancedPlayer like this in line 3: AdvancedPlayer = GameObject This should help a bit out for you. @coolfireking2
Your answer

Follow this Question
Related Questions
'AdvancedPlayer' does not exist in the current context 0 Answers
Can't access another script, think it may be due to namespace/public class ? 1 Answer
Getting errors while creating a custom terrain editor 0 Answers
"Unknown resolve error" 2 Answers
"The name 'Convert' does not exist in the current context" C# 2 Answers