public void Moved()
    {
        float thisDistance = Vector2.Distance(unit.position, _thisUnit.position);

        if (thisDistance > distance && thisDistance < maxDistance)
        {
            var position  = _thisUnit.position;
            var position1 = unit.position;
            var angle     = Vector2.Angle(Vector2.right, position1 - position);
            _thisUnit.eulerAngles = new Vector3(0f, 0f, position.y < position1.y ? angle : -angle);

            _thisMotor.GoToForward(_thisUnit.right);
        }
        else if (thisDistance > distance && thisDistance > maxDistance)
        {
            var     position = unit.position;
            Vector3 tpPoint  = new Vector3()
            {
                x = Random.Range(position.x - distance, position.x + distance),
                y = Random.Range(position.y - distance, position.y + distance)
            };

            _thisMotor.TpToPoint(tpPoint);
        }
        else
        {
            this.RandomMoved(distance / 4, distance / 2);
        }
    }
Exemplo n.º 2
0
    public void Moved()
    {
        var  position = _thisUnit.position;
        var  angle    = Vector2.Angle(Vector2.right, pointMoved[_currentPosition] - position);
        bool forward  = position.y < pointMoved[_currentPosition].y;

        _thisMotor.RotateAngle(angle, forward);

        if (Vector2.Distance(pointMoved[_currentPosition], _thisUnit.position) > 0.1)
        {
            _thisMotor.GoToForward(_thisUnit.right);
        }
        else if (_back == false)
        {
            if (_currentPosition < pointMoved.Length - 1)
            {
                _currentPosition++;
            }
            else
            {
                _back = true;
            }
        }
        else if (_back == true)
        {
            if (_currentPosition > 0)
            {
                _currentPosition--;
            }
            else
            {
                _back = false;
            }
        }
    }