コード例 #1
0
    /// <summary>
    /// Checks collider to know what the hero is interacting with and acts accordingly.
    /// </summary>
    /// <param name = "other">Collided object</param>
    void OnTriggerEnter2D(Collider2D other)
    {
        if (!isInFight)
        {
            // for map transition

            /*if (other.tag == "Teleporter") {
             *  GameManager.instance.nextSpawnPoint = col.spawnPointName;
             *  GameManager.instance.sceneToLoad = col.sceneToLoad;
             * }*/
            // for interaction with items
            if (other.tag == "Item")
            {
            }
            // for battle
            if (other.tag == "Enemy")
            {
                //isInFight = true;
                GameObject.Find("Blende").GetComponent <BlendenController>().blenden();
                isInFight = true;
                GameManager.instance.gui.SetActive(true);
                BattleStateMachine  bsm   = GameObject.Find("BattleManager").GetComponent <BattleStateMachine>();
                CharacterAmountType enemy = other.gameObject.GetComponent <CharacterAmountType>();
                CharacterAmountType hero  = this.gameObject.GetComponent <CharacterAmountType>();
                bsm.SpawnCharacters(enemy.characters.Count, enemy.characters, spawnPointsEnemies, false);
                bsm.SpawnCharacters(hero.characters.Count, hero.characters, spawnPointsHeros, true);
                this.gameObject.SetActive(false);
                other.gameObject.SetActive(false);
                GameManager.instance.collidedEnemy = other.gameObject;
                GameManager.PlayMusic(bsm.GetComponent <AudioSource>());
            }
        }
    }
コード例 #2
0
    /// <summary>
    /// Checks collider to know what the hero is interacting with and acts accordingly.
    /// </summary>
    /// <param name = "other">Collided object</param>
    void OnTriggerEnter2D(Collider2D other)
    {
        if (!isInFight)
        {
            // for map transition

            /*if (other.tag == "Teleporter") {
             *  GameManager.instance.nextSpawnPoint = col.spawnPointName;
             *  GameManager.instance.sceneToLoad = col.sceneToLoad;
             * }*/
            // for interaction with items
            if (other.tag == "Item")
            {
            }
            if (other.tag == "NextLevel")
            {
                GameManager gm = GameObject.Find("Game Manager").GetComponent <GameManager>();
                gm.LoadNextScene("DesertLevel");
            }
            // for battle
            if (other.tag == "Enemy")
            {
                GameObject.Find("Blende").GetComponent <BlendenController>().blenden();
                isInFight = true;
                GameManager.instance.gui.SetActive(true);
                BattleStateMachine  bsm   = GameObject.Find("BattleManager").GetComponent <BattleStateMachine>();
                CharacterAmountType enemy = other.gameObject.GetComponent <CharacterAmountType>();
                CharacterAmountType hero  = this.gameObject.GetComponent <CharacterAmountType>();
                bsm.SpawnCharacters(enemy.characters.Count, enemy.characters, spawnPointsEnemies, false);
                bsm.SpawnCharacters(hero.characters.Count, hero.characters, spawnPointsHeros, true);
                this.gameObject.SetActive(false);
                other.gameObject.SetActive(false);
                GameManager.instance.collidedEnemy = other.gameObject;

                if (other.gameObject.name == "JnR_Robot(Clone)")
                {
                    AudioClip audio = (AudioClip)Resources.Load("Audio/Music/Battle_Boss_Loop");
                    bsm.GetComponent <AudioSource>().clip = audio;
                    GameManager.PlayMusic(bsm.GetComponent <AudioSource>());
                }
                else
                {
                    GameManager.PlayMusic(bsm.GetComponent <AudioSource>());
                }
            }
        }
    }