コード例 #1
0
 private void HandleFireProjectile()
 {
     if (Input.GetButton("Fire1"))
     {
         if (delay == 0)
         {
             projectileLauncher.Fire((Vector2)transform.position + (new Vector2(0, 0.6f)));
         }
         else
         {
             ThrottleFire();
         }
     }
 }
コード例 #2
0
    void Update()
    {
        if (cooldown <= 0)
        {
            projectileLauncher.Fire((Vector2)transform.position - (new Vector2(0, 0.6f)));
            cooldown = Random.Range(attackFrequency.Min, attackFrequency.Max);
        }

        cooldown -= Time.deltaTime;
    }
コード例 #3
0
 public void Shoot(bool state)
 {
     if (state)
     {
         weapon.Fire();
     }
     else
     {
         weapon.HaltFire();
     }
 }
コード例 #4
0
 //animation event
 public void ReleaseFireball()
 {
     fireBall.Fire(target.transform.position + new Vector3(0f, 8f, 0f));
 }
コード例 #5
0
    private void AIAction()
    {
        if (AICurrentUpTime < AIUpTime)
        {
            Vector3 targetVector = target.transform.position - transform.position;
            targetVector.Set(targetVector.x, 0f, targetVector.z);

            if (targetVector.magnitude <= aggroRadius && hostile)
            {
                Vector3 direction    = targetVector.normalized;
                float   distance     = targetVector.magnitude;
                Bounds  targetBounds = target.GetComponent <Collider>().bounds;

                //face target
                AdjustFacing(targetVector);

                if (AIPathStrategy < 0.4f)
                {
                    //approach x
                    direction = new Vector3(direction.x, 0f, direction.z / 3f).normalized;
                }
                else if (AIPathStrategy < 0.8f)
                {
                    //approach z
                    direction = new Vector3(direction.x / 3f, 0f, direction.z).normalized;
                }
                else
                {
                    //align z but create distance for ranged attack
                    direction = new Vector3(-direction.x, 0f, direction.z);
                    if (distance > aggroRadius * 0.6f)
                    {
                        direction = Vector3.zero;
                    }
                }
                if (distance > targetBounds.extents.x + cldr.bounds.extents.x && direction != Vector3.zero)
                {
                    rb.velocity = direction * groundSpeed;
                }
                if (Mathf.Abs(targetVector.x) < spiderWeb.range && Mathf.Abs(targetVector.z) < targetBounds.extents.z && spiderWeb.ready && AIActionStrategy > 0.6f)
                {
                    spiderWeb.Fire();
                    SoundManager.PlayOnce(webLaunchSound);
                }
            }
            else
            {
                if (allowPatrol)
                {
                    Vector2 currentPos = new Vector2(transform.position.x, transform.position.z);
                    Vector2 velocity2D = Vector2.zero;
                    if ((randomPatrolPoint - currentPos).magnitude > 0.5f)
                    {
                        velocity2D  = (randomPatrolPoint - currentPos).normalized * groundSpeed;
                        rb.velocity = new Vector3(velocity2D.x, rb.velocity.y, velocity2D.y);
                    }
                    AdjustFacing(velocity2D);
                }
            }
        }
        else
        {
            if (AICurrentDownTime >= AIDownTime)
            {
                AICurrentDownTime = 0f;
                AICurrentUpTime   = 0f;
                AIPathStrategy    = Random.value;
                AIActionStrategy  = Random.value;
                AIRandomPatrolPoint();
            }
        }
    }
コード例 #6
0
    void Update()
    {
        if ((point.position - transform.position).magnitude < pointChangeCal)
        {
            closestPoint--;
            if (closestPoint < 1)
            {
                closestPoint = pointsOfIntrest.Count;
            }
            point = pointsOfIntrest[pointsOfIntrest.Count - closestPoint];
        }

        if (Time.time - lastRetreatTime > retreatDuration)
        {
            if (health.health < 2)
            {
                movementState   = AIState.Routing;
                lastRetreatTime = Time.time;
            }
            else if (closestEnemy != null)
            {
                Vector3 enemyDiff = closestEnemy.position - transform.position;
                if (enemyDiff.magnitude < 10 && Time.time - lastKiteTime > kiteDuration)
                {
                    movementState = AIState.Kite;
                    motor.Turn(enemyDiff);
                    gun.Fire(transform.forward);
                }
                else if (enemyDiff.magnitude < 20)
                {
                    movementState = AIState.Attacking;
                    motor.Turn(enemyDiff);
                    gun.Fire(transform.forward);
                }
            }
            else if (movementState >= AIState.Attacking)
            {
                movementState = AIState.ToPoint;
            }
        }

        switch (movementState)
        {
        case AIState.ToPoint:
            if (point == null)
            {
                break;
            }
            Vector3 pointDir = point.position - transform.position;
            motor.Move(pointDir);
            break;

        case AIState.Attacking:
            if (closestEnemy != null)
            {
                lastKiteTime = Time.time;
                Vector3 attackDir = closestEnemy.position - transform.position;
                motor.Move(attackDir);
            }
            break;

        case AIState.Kite:
            if (closestEnemy != null)
            {
                Vector3 kiteDir = transform.position - closestEnemy.position;
                motor.Move(kiteDir);
            }
            break;

        case AIState.Routing:
            Vector3 retreatDir = pointsOfIntrest[0].position - transform.position;
            motor.Move(retreatDir);
            break;

        case AIState.Holding:
            motor.Move(Vector3.zero);
            break;
        }
    }
コード例 #7
0
ファイル: Turret.cs プロジェクト: MrMeik/OU_Game_Jam_2021
    void Update()
    {
        if (status == Status.Disabled)
        {
            return;
        }
        if (status != Status.Firing)
        {
            weapon.HaltFire();
        }
        switch (status)
        {
        case Status.Hidden:
            if (retargetCurrentTime >= retargetTime)
            {
                if (CanSeePlayer())
                {
                    Deploy();
                }
                retargetCurrentTime -= retargetTime;
            }
            else
            {
                retargetCurrentTime += Time.deltaTime;
            }
            break;

        case Status.Deployed:
            if (retargetCurrentTime >= retargetTime)
            {
                if (CanSeePlayer())
                {
                    status = Status.Firing;
                }
                retargetCurrentTime -= retargetTime;
            }
            else
            {
                retargetCurrentTime += Time.deltaTime;
            }
            break;

        case Status.Firing:
            weapon.transform.LookAt(PlayerController.Instance.Position(), Vector3.up);
            weapon.Fire();
            if (retargetCurrentTime >= retargetTime)
            {
                if (!CanSeePlayer())
                {
                    status = Status.Deployed;
                }
                retargetCurrentTime -= retargetTime;
            }
            else
            {
                retargetCurrentTime += Time.deltaTime;
            }
            break;

        case Status.Shielding:
            if (shieldingId == -1)    //shield.IsOn() && !shield.IsEngaging())
            {
                shieldingId = LeanTween.delayedCall(1f, () => StopShielding()).id;
            }
            break;
        }
    }