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 /
avatar image
0
Question by Jaidan · Feb 10, 2015 at 05:55 PM · c#objectreferencenon-staticrequired

An object reference is required to access non-static member

I have a error when i have some code: here is it:

using UnityEngine; using System.Collections;

public class CollisionPlayer : MonoBehaviour {

 void Start(){

     IfLoose ifloose = GetComponent<IfLoose> ();

     if (Input.GetKeyDown("space"))
         IfLoose.StartLooseGame ();
 }

}

I am trying to access a public void from another script but it is not working? Any ideas?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by giulio-pierucci · Feb 10, 2015 at 05:59 PM

Casing error, Ifloose (class) instead of ifloose (instance)

 void Start(){
  
      IfLoose ifloose = GetComponent<IfLoose> ();
  
      if (Input.GetKeyDown("space"))
          ifloose.StartLooseGame ();
  }
Comment
Add comment · Show 6 · 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 Jaidan · Feb 10, 2015 at 06:06 PM 0
Share

Ah Thank you but then i get another error messgae:

The best overloaded method match for UnityEngine.$$anonymous$$onoBehaviour.StartCoroutine(System.Collections.IEnumerator)' has some invalid arguments AND: error CS1503: Argument #1' cannot convert method group' expression to type System.Collections.IEnumerator'

I dont know what these mean so i cant begin to solve the problem. Thanks

avatar image giulio-pierucci · Feb 10, 2015 at 06:52 PM 0
Share

Post the script (at least some rows) and i'll tell you what is wrong

avatar image Jaidan · Feb 10, 2015 at 07:19 PM 0
Share

The errors are all for this script:

using UnityEngine; using System.Collections;

public class IfLoose : $$anonymous$$onoBehaviour {

 bool AudioListener.pause;
 public GameObject loose$$anonymous$$enuPanel;
 private Animator anim;
 
 void Start () {

     Time.timeScale = 1;
     anim = loose$$anonymous$$enuPanel.GetComponent<Animator>();
     anim.enabled = false;
 }
 
 public IEnumerator LooseGame(){

     anim.enabled = true;
     anim.Play("Loose$$anonymous$$enu");
     Time.timeScale = 0;
     AudioListener.pause = true;
     return null;
 }

 public void StartLooseGame(){

     StartCoroutine(LooseGame);
 }
 

}

avatar image Jaidan · Feb 10, 2015 at 07:19 PM 0
Share

And im trying to call the coroutine of of this script:

using UnityEngine; using System.Collections;

public class CollisionPlayer : $$anonymous$$onoBehaviour {

 void Start(){

     IfLoose ifloose = GetComponent<IfLoose> ();

     if (Input.Get$$anonymous$$eyDown("space"))
         ifloose.StartLooseGame ();
 }


}

avatar image giulio-pierucci · Feb 10, 2015 at 08:11 PM 0
Share

StartCoroutine(LooseGame); is incorrect

correct form:

 StartCoroutine("LooseGame");

or

 StartCoroutine(LooseGame());


Show more comments

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

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

C# Null Object Reference - Driving me mad! 1 Answer

Get variable from seperate script. 1 Answer

Distribute terrain in zones 3 Answers

C# transfer reference of object 2 Answers

reference is required to access non-static member `CarController.Update()' 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