Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by coolfireking2 · May 17, 2013 at 08:06 PM · context

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

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ExTheSea · May 17, 2013 at 08:15 PM 0
Share

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.

avatar image coolfireking2 · May 17, 2013 at 08:36 PM 0
Share

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;        
 }    
     
     
 }
 
avatar image ExTheSea · May 17, 2013 at 08:39 PM 0
Share

What is not working correctoly? are you getting any errors? Please give us more detail about your issue.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges