Exemplo n.º 1
0
    void FixedUpdate()                                                                        //TODO: states
    {
        if (Vector2.Distance(m_controlledEnemy.position, target.position) <= m_shooter.Range) //TODO: use LOS to move around obstacles
        {
            bool    hitTarget  = false;
            Vector2 targetDire = ((Vector2)target.position - m_controlledEnemy.position).normalized;

            Debug.DrawRay(m_controlledEnemy.position, targetDire * m_shooter.Range, Color.red);
            var hit = Physics2D.Raycast(m_controlledEnemy.position, targetDire, m_shooter.Range, myLayerMask);
            hitTarget = hit.collider?.gameObject == target.gameObject;

            if (hitTarget)
            {
                StopMoving();
                RotateEnemy(targetDire);
                m_shooter.ShootAt(target);
                return;
            }
        }

        MoveAimToTarget();
    }