예제 #1
0
    public IEnumerator AttackClosestCycle(Turret turret, Action onDone)
    {
        Transform target = GameManager.Instance.targeting.GetClosestTarget(turret.transform.position);

        if (target == null)
        {
            if (onDone != null)
            {
                onDone();
            }
            yield return(null);
        }
        while (target != null)
        {
            target         = GameManager.Instance.targeting.GetClosestTarget(turret.transform.position);
            turret.aiState = "attacking target " + target;
            if (target != null)
            {
                turret.Aim(target.position, target.GetComponent <Fighter>().MovePrediction);
                turret.gun.Shoot(turret.data);
            }
            yield return(null);
        }
        yield return(null);

        if (onDone != null)
        {
            onDone();
        }
    }
예제 #2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (!target)
        {
            target = targetFinder.FindTarget(transform.position, range, targetLayerMask);
            turret.SetIdle();
        }
        else
        {
            turret.Aim(target.position);
            turret.Fire();

            if (Vector3.Distance(transform.position, target.position) > range)
            {
                target = null;
            }
        }
    }
예제 #3
0
        public NodeResult Evaluate(Turret turret, IEnumerable <Transform> targets)
        {
            if (turret.Target == null)
            {
                return(NodeResult.Failure);
            }

            // Aim at target.
            var turretForward     = turret.transform.forward;
            var directionToTarget = Vector3.Normalize(turret.Target.position - turret.transform.position);

            turret.Aim(directionToTarget);

            // Check if we are inside the threshold.
            var angleToTarget = Vector3.Angle(turretForward, directionToTarget);

            return(angleToTarget <= this.maxAngle ? NodeResult.Success : NodeResult.Running);
        }
예제 #4
0
    private void Update()
    {
        if (Application.platform != RuntimePlatform.Android)
        {
            m_moveInput   = Input.GetAxis("Horizontal");
            m_rotateInput = Input.GetAxis("Rotate") != 0 ? Input.GetAxis("Rotate") : Input.GetAxis("Mouse X");
            if (!EventSystem.current.IsPointerOverGameObject())
            {
                m_fireInput = Input.GetMouseButtonDown(0) || Input.GetKeyDown("space");
            }
        }

        m_turret.Move(m_moveInput);
        m_turret.Rotate(m_rotateInput);
        m_turret.Aim();
        if (m_fireInput)
        {
            m_turret.Fire();
            m_fireInput = false;
        }
    }
예제 #5
0
 public NodeResult Evaluate(Turret turret, IEnumerable <Transform> targets)
 {
     turret.Aim(turret.InitialRotation * Vector3.forward);
     return(NodeResult.Running);
 }