Exemplo n.º 1
0
        private void PlaceEnemies(Double left, Double top)
        {
            Enemy1.Move(Enemy1.Left + left, Enemy1.Top + top);
            Enemy2.Move(Enemy1.Left + GameConfigurations.EnemyWidth * 1.5, Enemy1.Top);
            Enemy3.Move(Enemy2.Left + GameConfigurations.EnemyWidth * 1.5, Enemy1.Top);
            Enemy4.Move(Enemy3.Left + GameConfigurations.EnemyWidth * 1.5, Enemy1.Top);

            Enemy5.Move(Enemy1.Left * 1.5, Enemy1.Top + GameConfigurations.EnemyHeight * 1.5);
            Enemy6.Move(Enemy5.Left + GameConfigurations.EnemyWidth * 1.5, Enemy5.Top);
            Enemy7.Move(Enemy6.Left + GameConfigurations.EnemyWidth * 1.5, Enemy5.Top);
            Enemy8.Move(Enemy7.Left + GameConfigurations.EnemyWidth * 1.5, Enemy5.Top);

            Enemy9.Move(Enemy1.Left * 1.25, Enemy5.Top + GameConfigurations.EnemyHeight * 1.5);
            Enemy10.Move(Enemy9.Left + GameConfigurations.EnemyWidth * 1.5, Enemy9.Top);
            Enemy11.Move(Enemy10.Left + GameConfigurations.EnemyWidth * 1.5, Enemy9.Top);
            Enemy12.Move(Enemy11.Left + GameConfigurations.EnemyWidth * 1.5, Enemy9.Top);

            Enemy13.Move(Enemy1.Left * 1.5, Enemy10.Top + GameConfigurations.EnemyHeight * 1.5);
            Enemy14.Move(Enemy13.Left + GameConfigurations.EnemyWidth * 1.5, Enemy13.Top);
            Enemy15.Move(Enemy14.Left + GameConfigurations.EnemyWidth * 1.5, Enemy13.Top);
            Enemy16.Move(Enemy15.Left + GameConfigurations.EnemyWidth * 1.5, Enemy13.Top);

            Enemy17.Move(Enemy1.Left, Enemy13.Top + GameConfigurations.EnemyHeight * 1.5);
            Enemy18.Move(Enemy17.Left + GameConfigurations.EnemyWidth * 1.5, Enemy17.Top);
            Enemy19.Move(Enemy18.Left + GameConfigurations.EnemyWidth * 1.5, Enemy17.Top);
            Enemy20.Move(Enemy19.Left + GameConfigurations.EnemyWidth * 1.5, Enemy17.Top);
        }
    void Start()
    {
        _enemy6 = GameObject.Find("Enemy6").GetComponent <Enemy6>();

        if (_enemy6 == null)
        {
            Debug.LogError("The Enemy6 script is null.");
        }
    }
Exemplo n.º 3
0
    void UpdateTarget()
    {
        GameObject[] enemies          = GameObject.FindGameObjectsWithTag(enemyTag);
        GameObject[] enemies2         = GameObject.FindGameObjectsWithTag(enemyTag2);
        float        shortestDistance = Mathf.Infinity;
        GameObject   nearestEnemy     = null;

        foreach (GameObject enemy in enemies)
        {
            float distanceToEnemy = Vector3.Distance(transform.position, enemy.transform.position);
            if (distanceToEnemy < shortestDistance)
            {
                shortestDistance = distanceToEnemy;
                nearestEnemy     = enemy;
            }
        }

        foreach (GameObject enemy in enemies2)
        {
            float distanceToEnemy = Vector3.Distance(transform.position, enemy.transform.position);
            if (distanceToEnemy < shortestDistance)
            {
                shortestDistance = distanceToEnemy;
                nearestEnemy     = enemy;
            }
        }

        if (nearestEnemy != null && shortestDistance <= range)
        {
            target       = nearestEnemy.transform;
            targetEnemy  = nearestEnemy.GetComponent <Enemy5> ();
            targetEnemy2 = nearestEnemy.GetComponent <Enemy6> ();
        }
        else
        {
            target       = null;
            targetEnemy  = null;
            targetEnemy2 = null;
        }
    }
Exemplo n.º 4
0
    void OnTriggerEnter2D(Collider2D col)
    {
        if (col.tag == "Enemy")
        {
            Enemy e = col.gameObject.GetComponent <Enemy>();
            if (e != null)
            {
                if (!(e.GameplayState == 3))
                {
                    e.GameplayState = 3;
                    e.AnimState     = 3;
                    e.curFrame      = 0;
                    level.GetComponent <levelManager>().enemycount--;
                    AudioSource.PlayClipAtPoint(ed, new Vector3(0, 0, 0), vol);
                }
                else
                {
                    e.GameplayState = 0;
                    e.AnimState     = 0;
                    e.curFrame      = 0;
                    e.patterncount  = 0;
                    level.GetComponent <levelManager>().enemycount++;
                    e.GetComponent <SpriteRenderer>().enabled = true;
                    e.GetComponent <SpriteRenderer>().sprite  = e.IdleAnimations[0];
                    AudioSource.PlayClipAtPoint(eu, new Vector3(0, 0, 0), vol);
                }
                Destroy(gameObject);
                return;
            }

            Enemy1 e1 = col.gameObject.GetComponent <Enemy1>();
            if (e1 != null)
            {
                if (!(e1.GameplayState == 3))
                {
                    e1.GameplayState = 3;
                    e1.AnimState     = 3;
                    e1.curFrame      = 0;
                    level.GetComponent <levelManager>().enemycount--;
                    AudioSource.PlayClipAtPoint(ed, new Vector3(0, 0, 0), vol);
                }
                else
                {
                    e1.GameplayState = 0;
                    e1.AnimState     = 0;
                    e1.curFrame      = 0;
                    e1.patterncount  = 0;
                    level.GetComponent <levelManager>().enemycount++;
                    e1.GetComponent <SpriteRenderer>().enabled = true;
                    e1.GetComponent <SpriteRenderer>().sprite  = e1.IdleAnimations[0];
                    AudioSource.PlayClipAtPoint(eu, new Vector3(0, 0, 0), vol);
                }
                Destroy(gameObject);
                return;
            }
            Enemy2 e2 = col.gameObject.GetComponent <Enemy2>();
            if (e2 != null)
            {
                if (!(e2.GameplayState == 3))
                {
                    e2.GameplayState = 3;
                    e2.AnimState     = 3;
                    e2.curFrame      = 0;
                    level.GetComponent <levelManager>().enemycount--;
                    AudioSource.PlayClipAtPoint(ed, new Vector3(0, 0, 0), vol);
                }
                else
                {
                    e2.GameplayState = 0;
                    e2.AnimState     = 0;
                    e2.curFrame      = 0;
                    e2.patterncount  = 0;
                    level.GetComponent <levelManager>().enemycount++;
                    e2.GetComponent <SpriteRenderer>().enabled = true;
                    e2.GetComponent <SpriteRenderer>().sprite  = e2.IdleAnimations[0];
                    AudioSource.PlayClipAtPoint(eu, new Vector3(0, 0, 0), vol);
                }
                Destroy(gameObject);
                return;
            }
            Enemy3 e3 = col.gameObject.GetComponent <Enemy3>();
            if (e3 != null)
            {
                if (!(e3.GameplayState == 3))
                {
                    e3.GameplayState = 3;
                    e3.AnimState     = 3;
                    e3.curFrame      = 0;
                    level.GetComponent <levelManager>().enemycount--;
                    AudioSource.PlayClipAtPoint(ed, new Vector3(0, 0, 0), vol);
                }
                else
                {
                    e3.GameplayState = 0;
                    e3.AnimState     = 0;
                    e3.curFrame      = 0;
                    e3.patterncount  = 0;
                    level.GetComponent <levelManager>().enemycount++;
                    e3.GetComponent <SpriteRenderer>().enabled = true;
                    e3.GetComponent <SpriteRenderer>().sprite  = e3.IdleAnimations[0];
                    AudioSource.PlayClipAtPoint(eu, new Vector3(0, 0, 0), vol);
                }
                Destroy(gameObject);
                return;
            }
            Enemy4 e4 = col.gameObject.GetComponent <Enemy4>();
            if (e4 != null)
            {
                if (!(e4.GameplayState == 3))
                {
                    e4.GameplayState = 3;
                    e4.AnimState     = 3;
                    e4.curFrame      = 0;
                    level.GetComponent <levelManager>().enemycount--;
                    AudioSource.PlayClipAtPoint(ed, new Vector3(0, 0, 0), vol);
                }
                else
                {
                    e4.GameplayState = 0;
                    e4.AnimState     = 0;
                    e4.curFrame      = 0;
                    e4.patterncount  = 0;
                    level.GetComponent <levelManager>().enemycount++;
                    e4.GetComponent <SpriteRenderer>().enabled = true;
                    e4.GetComponent <SpriteRenderer>().sprite  = e4.IdleAnimations[0];
                    AudioSource.PlayClipAtPoint(eu, new Vector3(0, 0, 0), vol);
                }
                Destroy(gameObject);
                return;
            }
            Enemy5 e5 = col.gameObject.GetComponent <Enemy5>();
            if (e5 != null)
            {
                if (!(e5.GameplayState == 3))
                {
                    e5.GameplayState = 3;
                    e5.AnimState     = 3;
                    e5.curFrame      = 0;
                    level.GetComponent <levelManager>().enemycount--;
                    AudioSource.PlayClipAtPoint(ed, new Vector3(0, 0, 0), vol);
                }
                else
                {
                    e5.GameplayState = 0;
                    e5.AnimState     = 0;
                    e5.curFrame      = 0;
                    e5.patterncount  = 0;
                    level.GetComponent <levelManager>().enemycount++;
                    e5.GetComponent <SpriteRenderer>().enabled = true;
                    e5.GetComponent <SpriteRenderer>().sprite  = e5.IdleAnimations[0];
                    AudioSource.PlayClipAtPoint(eu, new Vector3(0, 0, 0), vol);
                }
                Destroy(gameObject);
                return;
            }
            Enemy6 e6 = col.gameObject.GetComponent <Enemy6>();
            if (e6 != null)
            {
                if (!(e6.GameplayState == 3))
                {
                    e6.GameplayState = 3;
                    e6.AnimState     = 3;
                    e6.curFrame      = 0;
                    level.GetComponent <levelManager>().enemycount--;
                    AudioSource.PlayClipAtPoint(ed, new Vector3(0, 0, 0), vol);
                }
                else
                {
                    e6.GameplayState = 0;
                    e6.AnimState     = 0;
                    e6.curFrame      = 0;
                    e6.patterncount  = 0;
                    level.GetComponent <levelManager>().enemycount++;
                    e6.GetComponent <SpriteRenderer>().enabled = true;
                    e6.GetComponent <SpriteRenderer>().sprite  = e6.IdleAnimations[0];
                    AudioSource.PlayClipAtPoint(eu, new Vector3(0, 0, 0), vol);
                }
                Destroy(gameObject);
                return;
            }

            BossEnemy e8 = col.gameObject.GetComponent <BossEnemy>();
            if (e8 != null)
            {
                if (!(e8.GameplayState == 3))
                {
                    e8.GameplayState = 3;
                    e8.AnimState     = 3;
                    e8.curFrame      = 0;
                    level.GetComponent <levelManager>().enemycount--;
                    AudioSource.PlayClipAtPoint(ed, new Vector3(0, 0, 0), vol);
                }
                else
                {
                    e8.GameplayState = 0;
                    e8.AnimState     = 0;
                    e8.curFrame      = 0;
                    e8.patterncount  = 0;
                    level.GetComponent <levelManager>().enemycount++;
                    e8.GetComponent <SpriteRenderer>().enabled = true;
                    e8.GetComponent <SpriteRenderer>().sprite  = e8.IdleAnimations[0];
                    AudioSource.PlayClipAtPoint(eu, new Vector3(0, 0, 0), vol);
                }
                Destroy(gameObject);
                return;
            }
        }
    }
 private void Start()
 {
     _gameManager  = GameObject.Find("Game Manager").GetComponent <GameManager>();
     _enemy6Script = Enemy6.GetComponent <Enemy6>();
 }
Exemplo n.º 6
0
    /// <summary>
    ///	单个敌人实例化
    /// </summary>
    public void NewEmeny(int i)
    {
        if (i == 1)
        {
            Emeny1 Newemeny = new Emeny1();
            Newemeny.initdate();
            EnemyHp       = Newemeny.GetHp;
            Agi           = Newemeny.Agi;
            Avd           = Newemeny.Avd;
            TextName.text = Newemeny.GetName;
            // enemyAi[0]=Newemeny;
            Headportrait = Newemeny.GetHeadportrait;
        }
        else if (i == 2)
        {
            Emeny2 Newemeny = new Emeny2();
            Newemeny.initdate();
            EnemyHp       = Newemeny.GetHp;
            TextName.text = Newemeny.GetName;
            Agi           = Newemeny.Agi;
            Avd           = Newemeny.Avd;
            Headportrait  = Newemeny.GetHeadportrait;
            // enemyAi[0]=Newemeny;
        }
        else if (i == 3)
        {
            Enemy3 Newemeny = new Enemy3();
            Newemeny.initdate();
            EnemyHp       = Newemeny.GetHp;
            Avd           = Newemeny.Avd;
            Agi           = Newemeny.Agi;
            Headportrait  = Newemeny.GetHeadportrait;
            TextName.text = Newemeny.GetName;
            // double [] b={0};
            // Debug.Log(enemyAi);
            // enemyAi[0]=Newemeny;
            enemyAi.Add(Newemeny);
        }
        else if (i == 4)
        {
            Enemy4 Newemeny = new Enemy4();
            Newemeny.initdate();
            EnemyHp       = Newemeny.GetHp;
            Headportrait  = Newemeny.GetHeadportrait;
            Agi           = Newemeny.Agi;
            Avd           = Newemeny.Avd;
            TextName.text = Newemeny.GetName;
            enemyAi.Add(Newemeny);
        }
        else if (i == 5)
        {
            Enemy5 Newemeny = new Enemy5();
            Newemeny.initdate();
            EnemyHp       = Newemeny.GetHp;
            Agi           = Newemeny.Agi;
            Avd           = Newemeny.Avd;
            Headportrait  = Newemeny.GetHeadportrait;
            TextName.text = Newemeny.GetName;
            enemyAi.Add(Newemeny);
        }
        else if (i == 6)
        {
            Enemy6 Newemeny = new Enemy6();
            Newemeny.initdate();
            EnemyHp       = Newemeny.GetHp;
            Agi           = Newemeny.Agi;
            Avd           = Newemeny.Avd;
            Headportrait  = Newemeny.GetHeadportrait;
            TextName.text = Newemeny.GetName;
            enemyAi.Add(Newemeny);
        }
        else if (i == 99)
        {
            Enemy99 Newemeny = new Enemy99();
            Newemeny.initdate();
            EnemyHp       = Newemeny.GetHp;
            Agi           = Newemeny.Agi;
            Avd           = Newemeny.Avd;
            Headportrait  = Newemeny.GetHeadportrait;
            TextName.text = Newemeny.GetName;
            // double [] b={0};
            Debug.Log(enemyAi);
            // enemyAi[0]=Newemeny;
            enemyAi.Add(Newemeny);
        }

        else
        {
            Debug.Log("Input wrong!The enmey" + i + " no Found!");
        }
        if (EnemyHp != 0)
        {
            EnemyMaxHp = EnemyHp;
            Update_HpSlider(EnemyMaxHp, EnemyHp);
        }
    }