Beispiel #1
0
    // Use this for initialization
    void Start()
    {
        replays         = new List <PlayerReplay>();
        isLevelFinished = false;

        GameObject player = GameObject.Find("Player");

        if (player)
        {
            recordingReplay = new PlayerReplay();
            PlayerReplayRecordBehaviour prrb = player.AddComponent <PlayerReplayRecordBehaviour>();
            prrb.SetReplay(recordingReplay);
            spawnPosition = player.transform.position;
        }
        else
        {
            Debug.LogError("No Player object in scene");
        }

        if (replayPrefab == null)
        {
            Debug.LogError("replayPrefab is missing from GameController");
        }

        if (playerPrefab == null)
        {
            Debug.LogError("playerPrefab is missing from GameController");
        }

        if (levelCompletePrefab == null)
        {
            Debug.LogError("levelCompletePrefab is missing from GameController");
        }
    }
Beispiel #2
0
    // Reset the level, immedietly
    public void ResetLevel()
    {
        levelResetTimer = 0.0f;

        // Send reset message to all game objects, slow but works
        GameObject[] allObjects = UnityEngine.Object.FindObjectsOfType <GameObject>();
        foreach (GameObject go in allObjects)
        {
            if (go.activeInHierarchy)
            {
                go.SendMessage("OnLevelReset", null, SendMessageOptions.DontRequireReceiver);
            }
        }

        GameObject player;

        // Remove any old copies of the player, should be destroyed already but
        // better safe than sorry
        foreach (GameObject p in GameObject.FindGameObjectsWithTag("Player"))
        {
            GameObject.Destroy(p);
        }

        // Store the replay
        if (recordingReplay != null)
        {
            replays.Add(recordingReplay);
            recordingReplay = null;
        }

        // Re-instantiate the player
        if (playerPrefab)
        {
            player = Instantiate(playerPrefab);
            player.transform.position = spawnPosition;

            // Reattach camera
            Camera.main.GetComponent <CameraBehaviour>().SetTarget(player.transform);

            PlayerReplayRecordBehaviour prrb = player.AddComponent <PlayerReplayRecordBehaviour>();
            recordingReplay = new PlayerReplay();
            prrb.SetReplay(recordingReplay);
        }

        SpawnGhosts();
    }