I have created some code that is meant to load my next level 20 seconds after the user has completed it, however i get an error "object reference is required to access a static function" however i need the function to be static to be able to call it when my helicopter doors open and the user can get in the helicopter. Can anyone help?
using UnityEngine;
using System.Collections;
public class GameManager : MonoBehaviour {
static bool _hasPlayerWon = false;
public static bool HasPlayerWon {get{return _hasPlayerWon;}}
Health _playerHealth;
public static void WinPlayer()
{
_hasPlayerWon = true;
Invoke("loadSplash",20.0f);
}
void loadSplash ()
{
Application.LoadLevel("splash1");
}
}
Create a field that holds a reference to the GameManager and call a Coroutine using that method that triggers the load.
Something like this:
static private GameManager instance;
void Awake()
{
instance = this;
}
public static void WinPlayer()
{
_hasPlayerWon = true;
instance.LoadLevel();
}
private void LoadLevel()
{
StartCoroutine( LoadCo() );
}
private IEnumerator LoadCo()
{
yield return new WaitForSeconds( 20.0 );
Application.LoadLevel("splash1");
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.