- Home /
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?
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 ();
  }
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
Post the script (at least some rows) and i'll tell you what is wrong
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);
 }
 
}
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 ();
 }
}
StartCoroutine(LooseGame); is incorrect
correct form:
 StartCoroutine("LooseGame");
or
 StartCoroutine(LooseGame());
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                