Example #1
0
    void Start()
    {
        isEnded = false;

        // Check parameters
        if (randomGuySpawns == null || randomGuySpawns.Length == 0) Debug.LogError("Missing randomGuySpawns!");
        if (randomGuyPrefab == null) Debug.LogError("Missing RandomGuy prefab!");
        if (bonusPrefab == null) Debug.LogError("Missing Bonus prefab!");
        if (coconutSpawn == null) Debug.LogError("Missing coconutSpawn!");

        gui = FindObjectOfType<GameGUI>();
        if (gui == null) Debug.LogError("Missing GUI!");

        music = FindObjectOfType<AudioSource>();

        // Initialize
        enemySpawnCooldown = Random.Range(minSpawnCooldownInSeconds, maxSpawnCooldownInSeconds);
        bonusCooldown = Random.Range(minBonusSpawnFrequency, maxBonusSpawnFrequency);

        slowmotionRemainingTime = slowmotionTotalTimeInSeconds;

        timeleft = time;
        score = 0;
        combo = 1;

        // Create a parent for a proper hierarchy
        randomGuysParent = new GameObject("Random Guys").transform;
        bonusParent = new GameObject("Bonuses").transform;
        coconutsParent = new GameObject("Coconuts").transform;

        fakeCoconuts = new List<FakeCoconutScript>(FindObjectsOfType<FakeCoconutScript>());

        // Instantiate coconut
        StartCoroutine(RespawnCoconut(1f));

        gui.SetVisible(true);
        DisplayMessage(MessageType.Start);
    }