Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Mar 29, 2017 at 04:17 PM by Bunny83 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by vcjr12 · Jul 08, 2013 at 08:37 PM · classclassesfunctions

The name '' does not exist in the current context

So what I'm trying to do is call a function from another script.

 public class Manager  
 {
          // Use this for initialization
      void Start()
         {
         SetPlayerPosition();
     }
 }
 


okay that's the Manager Sample , here the other

 public class Player : MonoBehaviour 
 {
     
    
     // Use this to set Player Position
      public void SetPlayerPosition()
      {
       transform.position = new Vector3(150, 0, 5);
      }
 
 }

I know this might be a simple question but this is bugging me since Ive done it before, I might even answer this myself after further research but just to post in case someone has same problem in future.

Note: The error is on the Manager.cs "The name 'SetPlayerPosition' does not exist in the current context"

Comment
Comments Locked
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

2 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by vcjr12 · Jul 08, 2013 at 09:12 PM

I tried this and it worked thanks for your help.

  void Start()
 {
         GameObject player = GameObject.FindGameObjectWithTag("Player");
         player.GetComponent<Player>().SetPlayerPosition();
 }
 
Comment
Comments Locked · Show 2 · 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
avatar image jimmyRustler · Nov 02, 2015 at 01:25 AM 0
Share

Ohhh man. Feeling a little silly that I had mixed up a type I defined in my script rather than in scene editor (prefab.) You're awesome.

avatar image CrispySlap · Mar 29, 2017 at 03:08 PM 0
Share

YOU HELP $$anonymous$$E IS WELL!

avatar image
2

Answer by robertbu · Jul 08, 2013 at 08:50 PM

You need to create a reference to a specific instance of the Player script (i.e. to the game object it is attached to). The multiple ways to do this are covered here:

Accessing Other GameObjects

Then you will use a variable pointing to that instance of the script to make the access. Something like:

playerScript.SetPlayerPosition();

Comment
Comments Locked · Show 4 · 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
avatar image vcjr12 · Jul 08, 2013 at 09:00 PM 0
Share

i tried this Player.SetPlayerPosition playerStart = new Player.SetPlayerPosition(); but then I get Is a method bu tis being used as a type. But thanks Ill take a look

avatar image robertbu · Jul 08, 2013 at 09:11 PM 0
Share

Read the link. You don't use new() with $$anonymous$$onobehaviour. You need to either drag and drop in the Inspector, or you can use GameObject.Find() and GetComponent().

avatar image jesses.co.tt · Jan 21, 2016 at 04:55 PM 0
Share

dead link...

avatar image Bunny83 jesses.co.tt · Jan 21, 2016 at 11:12 PM 0
Share

fixed the link

Follow this Question

Answers Answers and Comments

20 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Instantiating gameObject with custom Class properties 1 Answer

Need my function to work with different lists of different values (classes) 1 Answer

The name `PurchaseManager' does not exist in the current context 0 Answers

Boolean from another script reads false even if i change it to true. 1 Answer

Making a Trait Mechanic? 1 Answer


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