void LateUpdate()
    {
        curDistance = Vector3.Distance(player.position, thisTransform.position);


        if (curDistance < distanceUntilCircle)
        {
            if (isHelicopter)
            {
                /*	if (Physics.SphereCast (thisTransform.position,50f, thisTransform.right, out hit, 7f))
                 *              turningDirection -= 0.005f;
                 *
                 *      if (Physics.SphereCast (thisTransform.position,50f, thisTransform.right * -1, out hit, 7f))
                 *              turningDirection += 0.005f;*/


                /*	if (Physics.SphereCast (thisTransform.position, 8f, thisTransform.rotation * Vector3.forward, out hit, 6f))
                 *              turningDirection += 0.1f;
                 *      else
                 *              turningDirection = 0f;
                 * //		thisTransform.position += thisTransform.rotation * Vector3.forward;*/

                thisTransform.position = Vector3.Lerp(thisTransform.position, new Vector3(Mathf.Cos(Time.time) * circleRadius + xOffset, upDistance, Mathf.Sin(Time.time) * circleRadius + zOffset) + player.position, Time.deltaTime * orbiterSpeed);

                //		thisTransform.position += Vector3.forward * turningDirection;
                //if (Physics.SphereCast (thisTransform.position, 20f, thisTransform.ba, out hit, 7f))
                //		thisTransform.localPosition += new Vector3 (0, 0, 10);//thisTransform.forward;
            }
            else
            {
                thisTransform.position = Vector3.Lerp(thisTransform.position, new Vector3(Mathf.Cos(Time.time) * circleRadius + xOffset, upDistance, Mathf.Sin(Time.time) * circleRadius + zOffset) + player.position, Time.deltaTime * orbiterSpeed);
            }



            timer += Time.deltaTime;



            transform.LookAt(player.position);


            if (timer > bulletDelay)
            {
                if (isHelicopter)
                {
                    EnemyBulletManager.BulletPosition(thisTransform.TransformPoint(Vector3.forward * 1.5f), transform.rotation, 3f);                        //Quaternion.LookRotation ((player.position - thisTransform.position) + player.forward * zOffset ), 0.3f);
                }
                else
                {
                    EnemyBulletManager.BulletPosition(thisTransform.TransformPoint(Vector3.forward * 1.5f), transform.rotation, bulletSpeed);                                      // Quaternion.LookRotation ((player.position - thisTransform.position) + player.forward * zOffset), 0.3f);
                }
                timer = 0;
            }
            return;
        }
        Vector3 dir = Vector3.Normalize(player.position - thisTransform.position);

        thisTransform.Translate(dir * speed);
    }
 void Awake()
 {
     if (instance)
     {
         Debug.Log("There are two EnemyBulletManager");
         return;
     }
     instance = this;
 }
Example #3
0
    private void Awake()
    {
        if (Instance != null)
        {
            Destroy(gameObject);
            return;
        }

        Instance = this;
    }
    private void Awake()
    {
        if (instance != null)
        {
            Destroy(instance.gameObject);
        }
        instance = this;

        bulletPools = new Dictionary <BulletType, Queue <EnemyBullet> >();
    }
    IEnumerator OnUpdate()
    {
        while (true)
        {
            yield return(new WaitForSeconds(bulletDelay + Random.Range(-magnitudeOffsetDelay, magnitudeOffsetDelay)));


            if (isDirectShoot)
            {
                EnemyBulletManager.BulletPosition(transform.TransformPoint(Vector3.forward * 1f), transform.rotation, bulletSpeed);
            }
            else
            {
                EnemyBulletManager.BulletPosition(transform.TransformPoint(Vector3.forward * 1.5f), Quaternion.LookRotation(playerTarget.transform.position - transform.position), bulletSpeed);
            }
        }
    }
Example #6
0
 // Start is called before the first frame update
 void Start()
 {
     bulletManager = FindObjectOfType <EnemyBulletManager>();
 }
 private void Awake()
 {
     lifeBulletsPool  = new LinkedList <EnemyBullet>();
     deatehBulletPool = new LinkedList <EnemyBullet>();
     instance         = this;
 }
Example #8
0
    // Update is called once per frame
    void Update()
    {
        if(!PlayerTransform)
        {
            PlayerManager pm = GameObject.FindObjectOfType<PlayerManager>();
            if(pm)
            {
                PlayerTransform = pm.transform;
            }
            else
            {
                return;
            }
        }

        if(!BulletManager)
        {
            BulletManager = GameObject.FindObjectOfType<EnemyBulletManager>();
        }

        float dist = Vector2.SqrMagnitude(PlayerTransform.position - transform.position);

        if(dist <= ViewRange*ViewRange || bSawPlayer)
        {
            bSawPlayer = true;
            Vector2 direction = (PlayerTransform.position - transform.position).normalized;
            //Walk towards the player
            if(dist > StopDistance * StopDistance)
            {
                m_RigidBody.velocity = new Vector2(direction.x * Speed * Time.deltaTime, direction.y * Speed * Time.deltaTime);
                m_Animator.SetFloat("XVelocity",m_RigidBody.velocity.x);
                m_Animator.SetFloat("YVelocity",m_RigidBody.velocity.y);
                m_MeleeAttack = false;
            }
            else
            {
                m_RigidBody.velocity = Vector2.zero;
                m_MeleeAttack = true;
            }

            switch(MyType)
            {
            case EnemyType.Melee:
                AttackTimer += Time.deltaTime;
                if(AttackTimer >= AttackDelay && m_MeleeAttack)
                {
                    AttackTimer = 0.0f;
                    GameplayUIManager.Instance.m_Player.TakeDamage(Damage);
                }
                break;
            case EnemyType.Ranged:
                AttackTimer += Time.deltaTime;
                if(AttackTimer >= AttackDelay)
                {
                    AttackTimer = 0.0f;
                    BulletManager.FireBullet(transform.position, direction, Damage, false);
                }
                break;
            case EnemyType.Boss:
                AttackTimer += Time.deltaTime;
                if(AttackTimer >= AttackDelay)
                {
                    AttackTimer = 0.0f;
                    BulletManager.FireBullet(transform.position, direction, Damage, true);

                    switch(BulletManager.GetComponent<LevelBuilder>().World)
                    {
                    case 1:
                    {
                        Vector2 newvec = new Vector2(direction.x + 0.3f,
                                                     direction.y + 0.3f);
                        newvec.Normalize();
                        BulletManager.FireBullet(transform.position, newvec, Damage, true);

                        Vector2 newvec1 = new Vector2(direction.x - 0.3f,
                                                     direction.y - 0.3f);
                        newvec1.Normalize();
                        BulletManager.FireBullet(transform.position, newvec1, Damage, true);
                    }
                        break;
                    case 2:
                    {
                        Vector2 newvec = new Vector2(direction.x + 0.4f,
                                                     direction.y + 0.4f);
                        newvec.Normalize();
                        BulletManager.FireBullet(transform.position, newvec, Damage, true);

                        Vector2 newvec1 = new Vector2(direction.x - 0.4f,
                                                      direction.y - 0.4f);
                        newvec1.Normalize();
                        BulletManager.FireBullet(transform.position, newvec1, Damage, true);
                        goto case 1;
                    }

                    case 3:
                    {
                        Vector2 newvec = new Vector2(direction.x + 0.5f,
                                                     direction.y + 0.5f);
                        newvec.Normalize();
                        BulletManager.FireBullet(transform.position, newvec, Damage, true);

                        Vector2 newvec1 = new Vector2(direction.x - 0.5f,
                                                      direction.y - 0.5f);
                        newvec1.Normalize();
                        BulletManager.FireBullet(transform.position, newvec1, Damage, true);
                        goto case 2;
                    }
                        break;
                    case 4:
                    {
                        Vector2 newvec = new Vector2(direction.x + 0.2f,
                                                     direction.y + 0.2f);
                        newvec.Normalize();
                        BulletManager.FireBullet(transform.position, newvec, Damage, true);

                        Vector2 newvec1 = new Vector2(direction.x - 0.2f,
                                                      direction.y - 0.2f);
                        newvec1.Normalize();
                        BulletManager.FireBullet(transform.position, newvec1, Damage, true);

                        Vector2 newvec2 = new Vector2(direction.x + 0.1f,
                                                     direction.y + 0.1f);
                        newvec2.Normalize();
                        BulletManager.FireBullet(transform.position, newvec2, Damage, true);

                        Vector2 newvec3 = new Vector2(direction.x - 0.1f,
                                                      direction.y - 0.1f);
                        newvec3.Normalize();
                        BulletManager.FireBullet(transform.position, newvec3, Damage, true);

                        goto case 3;
                    }
                        break;
                    }
                }
                break;
            }

        }
        else
        {
            m_RigidBody.velocity = Vector2.zero;
        }
    }
Example #9
0
    // Update is called once per frame
    void Update()
    {
        if (!PlayerTransform)
        {
            PlayerManager pm = GameObject.FindObjectOfType <PlayerManager>();
            if (pm)
            {
                PlayerTransform = pm.transform;
            }
            else
            {
                return;
            }
        }

        if (!BulletManager)
        {
            BulletManager = GameObject.FindObjectOfType <EnemyBulletManager>();
        }

        float dist = Vector2.SqrMagnitude(PlayerTransform.position - transform.position);

        if (dist <= ViewRange * ViewRange || bSawPlayer)
        {
            bSawPlayer = true;
            Vector2 direction = (PlayerTransform.position - transform.position).normalized;
            //Walk towards the player
            if (dist > StopDistance * StopDistance)
            {
                m_RigidBody.velocity = new Vector2(direction.x * Speed * Time.deltaTime, direction.y * Speed * Time.deltaTime);
                m_Animator.SetFloat("XVelocity", m_RigidBody.velocity.x);
                m_Animator.SetFloat("YVelocity", m_RigidBody.velocity.y);
                m_MeleeAttack = false;
            }
            else
            {
                m_RigidBody.velocity = Vector2.zero;
                m_MeleeAttack        = true;
            }

            switch (MyType)
            {
            case EnemyType.Melee:
                AttackTimer += Time.deltaTime;
                if (AttackTimer >= AttackDelay && m_MeleeAttack)
                {
                    AttackTimer = 0.0f;
                    GameplayUIManager.Instance.m_Player.TakeDamage(Damage);
                }
                break;

            case EnemyType.Ranged:
                AttackTimer += Time.deltaTime;
                if (AttackTimer >= AttackDelay)
                {
                    AttackTimer = 0.0f;
                    BulletManager.FireBullet(transform.position, direction, Damage, false);
                }
                break;

            case EnemyType.Boss:
                AttackTimer += Time.deltaTime;
                if (AttackTimer >= AttackDelay)
                {
                    AttackTimer = 0.0f;
                    BulletManager.FireBullet(transform.position, direction, Damage, true);

                    switch (BulletManager.GetComponent <LevelBuilder>().World)
                    {
                    case 1:
                    {
                        Vector2 newvec = new Vector2(direction.x + 0.3f,
                                                     direction.y + 0.3f);
                        newvec.Normalize();
                        BulletManager.FireBullet(transform.position, newvec, Damage, true);

                        Vector2 newvec1 = new Vector2(direction.x - 0.3f,
                                                      direction.y - 0.3f);
                        newvec1.Normalize();
                        BulletManager.FireBullet(transform.position, newvec1, Damage, true);
                    }
                    break;

                    case 2:
                    {
                        Vector2 newvec = new Vector2(direction.x + 0.4f,
                                                     direction.y + 0.4f);
                        newvec.Normalize();
                        BulletManager.FireBullet(transform.position, newvec, Damage, true);

                        Vector2 newvec1 = new Vector2(direction.x - 0.4f,
                                                      direction.y - 0.4f);
                        newvec1.Normalize();
                        BulletManager.FireBullet(transform.position, newvec1, Damage, true);
                        goto case 1;
                    }

                    case 3:
                    {
                        Vector2 newvec = new Vector2(direction.x + 0.5f,
                                                     direction.y + 0.5f);
                        newvec.Normalize();
                        BulletManager.FireBullet(transform.position, newvec, Damage, true);

                        Vector2 newvec1 = new Vector2(direction.x - 0.5f,
                                                      direction.y - 0.5f);
                        newvec1.Normalize();
                        BulletManager.FireBullet(transform.position, newvec1, Damage, true);
                        goto case 2;
                    }
                    break;

                    case 4:
                    {
                        Vector2 newvec = new Vector2(direction.x + 0.2f,
                                                     direction.y + 0.2f);
                        newvec.Normalize();
                        BulletManager.FireBullet(transform.position, newvec, Damage, true);

                        Vector2 newvec1 = new Vector2(direction.x - 0.2f,
                                                      direction.y - 0.2f);
                        newvec1.Normalize();
                        BulletManager.FireBullet(transform.position, newvec1, Damage, true);

                        Vector2 newvec2 = new Vector2(direction.x + 0.1f,
                                                      direction.y + 0.1f);
                        newvec2.Normalize();
                        BulletManager.FireBullet(transform.position, newvec2, Damage, true);

                        Vector2 newvec3 = new Vector2(direction.x - 0.1f,
                                                      direction.y - 0.1f);
                        newvec3.Normalize();
                        BulletManager.FireBullet(transform.position, newvec3, Damage, true);

                        goto case 3;
                    }
                    break;
                    }
                }
                break;
            }
        }
        else
        {
            m_RigidBody.velocity = Vector2.zero;
        }
    }