Question by
bellwether · Jul 16, 2017 at 04:58 PM ·
movementbooleandelegate
Board game help [NEWB]
public class dice_roll : MonoBehaviour {
public List<Transform> BoardPosition = new List<Transform>();
//public Transform[] BoardPosition;
public int newPosition;
public int CurrentPosition = 0;
public int DiceValues;
//public dice_raycast Dice1;
//public dice_raycast Dice2;
public float speed = 3;
void Start()
{
if (BoardPosition.Count == 0)
BoardPosition.Add (GameObject.FindWithTag ("SquareBoardPosition").transform);
//BoardPosition [CurrentPosition].transform.position = transform.position;
}
void Update()
{
//Only update the position if the dice was rolled and the rolled bool is true if the dice is not moving anymore.
if (Input.GetKeyDown ("r")) {
DiceValues = Random.Range (1, 6); <-------- point of error.
newPosition = CurrentPosition + DiceValues; //Not Sure about this, it's get ran multiple times.
}
if (newPosition < BoardPosition.Count) {
//transform.position = BoardPosition[CurrentPosition].position;
transform.position = Vector3.MoveTowards (BoardPosition [newPosition].position,
BoardPosition [newPosition].transform.position, Time.deltaTime * speed);
if (transform.position == BoardPosition [newPosition].transform.position) {
CurrentPosition = newPosition;
}
//newPosition++;
print ("Dice: " + DiceValues + " position: " + CurrentPosition);
}
}
}
Corrected!
Comment
Answer by alankemp · Jul 19, 2017 at 09:55 PM
You probably want to set:
Dice1.rolled = false;
Inside your if statement so you know that you have already used the values from rolling the dice this time.
$$anonymous$$aybe the problem is in the code where you set rolled to true?
Are you sure you're only setting it true once and at the right time?
I did have that problem and i've fixed it but it still goes through all the spaces. I'll put up the dice code if that helps.