void Update()
    {
        if (moveToPoint == null)
        {
            moveToPoint = FindObjectOfType <Waypoint>();
            return;
        }

        if (Vector2.Distance(transform.position, moveToPoint.transform.position) <= distanceThreshold)
        {
            moveToPoint = moveToPoint.Next;
        }

        //Move towards grid position
        transform.position += (moveGrid.getPosition(posX, posY) - transform.position) * Time.deltaTime * speed;

        if (canMove)
        {
            MoveInGrid(moveToPoint.X, moveToPoint.Y);

            canMove = false;
        }
    }
Beispiel #2
0
 public void Start()
 {
     moveGrid           = FindObjectOfType <MovementGrid>();
     transform.position = moveGrid.getPosition(X, Y);
 }