Hey! I want the random number to get into the canvas that I want to create but I don’t know how to do it…
Can someone help me with how to get the random number; steps = Random.Range(1, 7); into the canvas.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class StoneCode : MonoBehaviour
{
public Route currentRoute;
int routePosition;
public int steps;
bool isMoving;
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) && !isMoving)
{
steps = Random.Range(1, 7);
Debug.Log("Dice Rolled " + steps);
StartCoroutine(Move());
//if (routePosition + steps < currentRoute.childNodeList.Count)
//{
// StartCoroutine(Move());
//}
//else
//{
// Debug.Log("Rolled number is too high");
//}
}
}
IEnumerator Move()
{
if (isMoving)
{
yield break;
}
isMoving = true;
while (steps > 0)
{
routePosition++;
routePosition %= currentRoute.childNodeList.Count;
Vector3 nextPos = currentRoute.childNodeList[routePosition].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, 10f * Time.deltaTime));
}
}