private void Start()
    {
        //This will call the SpawnIn function when the game starts (currently does nothing)
        SpawnIn();

        //This will repeat the Attack function once every four seconds indefinitely
        InvokeRepeating(nameof(Attack), 4, 4);

        //An example of how to write a string to the screen"
        ouputLog.OutputText("A " + monsters.myName + " approaches!");
    }
Example #2
0
    private void Start()
    {
        // Create the active heroes list.
        this.InstantiateRandomCharactersOntoSpawnPositions(this.heroLibrary, this.heroSpawnPoints, this.activeHeroes);

        // Create the active monsters list.
        this.InstantiateRandomCharactersOntoSpawnPositions(this.monsterLibrary, this.monsterSpawnPoints, this.activeMonsters);

        // Check some heroes and monsters have been created to battle. If not, end the game.
        if (this.activeHeroes.Count == 0 && this.activeMonsters.Count == 0)
        {
            this.EndBattle("There will be no battle today.");
            return;
        }

        // Call the Fight() method every four seconds until CancelInvoke() called  (* See Unity Scripting Reference "InvokeRepeating" for more)
        InvokeRepeating("Fight", 4, 4);

        // An example of how to write a string to the screen.
        ouputLog.OutputText("Let the battle begin...");
    }
    //This function should calculate and assign damage appropriately.
    //This function should also trigger the end of the game when appropriate.
    void Attack()
    {
        //assigns variables relevent to the cooldown bar
        float damage = 0f;
        float enemy1Health;
        float enemyResist;
        float hero1Health;
        float heroResist;

        if (characterStats.faction == "hero")
        {
            //This method may be quite slow/resource heavy, however, since this project is a single game scene, I am not overly worried about speed issues.
            if (GameObject.Find("Enemy1(Clone)").GetComponent <CharacterStats>().alive == true)
            {
                enemy1Health = GameObject.Find("Enemy1(Clone)").GetComponent <CharacterStats>().health;
                enemyResist  = GameObject.Find("Enemy1(Clone)").GetComponent <CharacterStats>().defence / 100f;
                damage       = characterStats.attack * enemyResist;
                GameObject.Find("Enemy1(Clone)").GetComponent <CharacterStats>().health -= (int)damage;
            }
            else if (GameObject.Find("Enemy2(Clone)").GetComponent <CharacterStats>().alive == true)
            {
                enemy1Health = GameObject.Find("Enemy2(Clone)").GetComponent <CharacterStats>().health;
                enemyResist  = GameObject.Find("Enemy2(Clone)").GetComponent <CharacterStats>().defence / 100f;
                damage       = characterStats.attack * enemyResist;
                GameObject.Find("Enemy2(Clone)").GetComponent <CharacterStats>().health -= (int)damage;
            }
            else if (GameObject.Find("Enemy3(Clone)").GetComponent <CharacterStats>().alive == true)
            {
                enemy1Health = GameObject.Find("Enemy3(Clone)").GetComponent <CharacterStats>().health;
                enemyResist  = GameObject.Find("Enemy3(Clone)").GetComponent <CharacterStats>().defence / 100f;
                damage       = characterStats.attack * enemyResist;
                GameObject.Find("Enemy3(Clone)").GetComponent <CharacterStats>().health -= (int)damage;
            }
            else
            {
                winner  = "Good Guys!";
                gameEnd = true;
            }

            if (gameEnd == false)
            {
                WriteText aa = Object.FindObjectOfType <WriteText>();
                aa.OutputText(characterStats.myName + " dealt " + damage + " damage to the enemy!");
            }
            else
            {
                WriteText aa = Object.FindObjectOfType <WriteText>();
                aa.OutputText("Woohoo! The good guys won!");
            }
        }
        else
        {
            if (GameObject.Find("Hero1(Clone)").GetComponent <CharacterStats>().alive == true)
            {
                hero1Health = GameObject.Find("Hero1(Clone)").GetComponent <CharacterStats>().health;
                heroResist  = GameObject.Find("Hero1(Clone)").GetComponent <CharacterStats>().defence / 100f;
                damage      = characterStats.attack * heroResist;
                GameObject.Find("Hero1(Clone)").GetComponent <CharacterStats>().health -= (int)damage;
            }
            else if (GameObject.Find("Hero2(Clone)").GetComponent <CharacterStats>().alive == true)
            {
                hero1Health = GameObject.Find("Hero2(Clone)").GetComponent <CharacterStats>().health;
                heroResist  = GameObject.Find("Hero2(Clone)").GetComponent <CharacterStats>().defence / 100f;
                damage      = characterStats.attack * heroResist;
                GameObject.Find("Hero2(Clone)").GetComponent <CharacterStats>().health -= (int)damage;
            }
            else if (GameObject.Find("Hero3(Clone)").GetComponent <CharacterStats>().alive == true)
            {
                hero1Health = GameObject.Find("Hero3(Clone)").GetComponent <CharacterStats>().health;
                heroResist  = GameObject.Find("Hero3(Clone)").GetComponent <CharacterStats>().defence / 100f;
                damage      = characterStats.attack * heroResist;
                GameObject.Find("Hero3(Clone)").GetComponent <CharacterStats>().health -= (int)damage;
            }
            else
            {
                gameEnd = true;
            }

            if (gameEnd == false)
            {
                WriteText aa = Object.FindObjectOfType <WriteText>();
                aa.OutputText(characterStats.myName + " dealt " + damage + " damage to the heroes!");
            }
            else
            {
                WriteText aa = Object.FindObjectOfType <WriteText>();
                aa.OutputText("Oh no! The bad guys won!");
            }
        }
    }