thanks to the internet I have a working boardgame mechanic that moves the player along the route i assign, but i want there to be intersections where you can go left or right. I cant for the love of me wrap my brain around how i would do it… i feel like i would need two methods that would get called from OnClick() from two icons, im picturing a left and right icon that would update or replace the currentRoute position, any help would be awesome. this is the movement script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Stone : MonoBehaviour
{
public Route currentRoute;
int routePosition;
public int steps;
public bool isMoving;
public int RoutePosition { get => routePosition; set => routePosition = value; }
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) && !isMoving)
RollThemDice();
}
IEnumerator Move()
{
if (isMoving)
{
yield break;
}
isMoving = true;
while (steps > 0)
{
Vector3 nextPos = currentRoute.childNodeList[RoutePosition + 1].position;
while (MoveToNextNode(nextPos)) { yield return null; }
yield return new WaitForSeconds(0.1f);
steps--;
RoutePosition++;
}
isMoving = false;
}
bool MoveToNextNode(Vector3 goal)
{
return goal != (transform.position = Vector3.MoveTowards(transform.position, goal, 2f * Time.deltaTime));
transform.position = Vector3.MoveTowards(transform.position, goal, 2f * Time.deltaTime);
}
public void RollThemDice()
{
steps = Random.Range(1, 7);
Debug.Log("Dice rolled" + steps);
if (RoutePosition + steps < currentRoute.childNodeList.Count)
{
StartCoroutine(Move());
}
else
{
Debug.Log("rolled Number is to high");
}
}
}