Exemplo n.º 1
0
 public void Shoot(Vector3 position, Vector3 velocity, RobotUnit target, int damage)
 {
     while (pool_[pool_idx_].alive_)
     {
         ++pool_idx_;
         if (pool_idx_ >= pool_.Length)
         {
             pool_idx_ = 0;
         }
     }
     pool_[pool_idx_].alive_    = true;
     pool_[pool_idx_].target    = target;
     pool_[pool_idx_].damage    = damage;
     pool_[pool_idx_].position_ = position;
     pool_[pool_idx_].velocity_ = velocity;
     if (target.type == RobotUnit.UnitType.Ally)
     {
         pool_[pool_idx_].id_ = Beam.Instance.spawn(0.8f /* width */, Beam.Type.LightBall);
     }
     else
     {
         pool_[pool_idx_].id_ = Beam.Instance.spawn(0.8f /* width */, Beam.Type.Bullet);
     }
     pool_[pool_idx_].cnt_ = 100;
 }
Exemplo n.º 2
0
        IEnumerator ScanAndAttackTarget()
        {
            while (true)
            {
                while (!target || !target.IsAlive)
                {
                    yield return(null);

                    List <RobotUnit> targets = FindObjectsOfType <RobotUnit>().Where(r => r && r.IsAlive && r.type != type).ToList();
                    enemyCount = targets.Count;
                    if (enemyCount > 0)
                    {
                        int random = Random.Range(0, enemyCount);
                        this.target = targets[random];
                    }
                    else
                    {
                        target = null;
                        break;
                    }

                    Quaternion lastRotation = turretT.localRotation;
                    if (target)
                    {
                        Quaternion wantedRot = Quaternion.LookRotation(target.targetT.position - turretT.position);
                        yield return(turretT.DORotateQuaternion(wantedRot, .5f).OnUpdate(() =>
                        {
                            turretT.localEulerAngles = new Vector3(turretT.localEulerAngles.x, 0, 0);
                        }).OnStart(() => IsAttacking = true).WaitForCompletion());
                    }
                }

                //if (moveTweener != null)
                //    moveTweener.Kill(true);

                //turretT.DOLookAt(target.targetT.position - targetT.position, .5f,AxisConstraint.X );
                if (target)
                {
                    IsAttacking = false;
                    yield return(new WaitForSeconds(Random.Range(.6f, 3f)));

                    IsAttacking = true;

                    if (!IsAlive || enemyCount == 0)
                    {
                        yield return(null);
                    }

                    yield return(new WaitUntil(() => !IsMoving));

                    var offsetRange = 3f;

                    for (int i = 0; i < 10; i++) //shoot 10 bullets
                    {
                        if (target)
                        {
                            var offset = new Vector3(Random.Range(-offsetRange, offsetRange),
                                                     Random.Range(-offsetRange, offsetRange),
                                                     Random.Range(-offsetRange, offsetRange));
                            Vector3 targetPostion  = target.targetT.position + offset;
                            Vector3 bulletVelocity = bulletSpeed * (targetPostion - this.targetT.position).normalized;
                            Beamer.Instance.Shoot(shootingT[i % shootingT.Length].position, bulletVelocity, target, 10 /*damage*/);
                            yield return(new WaitForSeconds(.07f));
                        }
                        else
                        {
                            break;
                        }
                    }

                    //Quaternion resetRotatation = lastRotation;
                    //yield return turretT.DORotateQuaternion(resetRotatation, .5f).OnUpdate(() =>
                    //{
                    //    turretT.localEulerAngles = new Vector3(turretT.localEulerAngles.x, 0, 0);
                    //}).WaitForCompletion();

                    IsAttacking = false;
                }
            }
        }