I have a UI element, RawImage, which I would like to change the texture of based on which random number between 1 and 6 is generated.
I want to change the picture of the dice, but I don't know how to access the RawImage.
This is what I've tried, I know it's terribly wrong, but have no clue how to handle this.
using UnityEngine;
using System.Collections;
using System;
public class RollTheDice : MonoBehaviour {
public GameObject[] dices;
public void OnClick(){
System.Random dice = new System.Random ();
int dicePoints = dice.Next (1, 7);
Debug.Log (dicePoints);
if (dicePoints == 1) {
GetComponent<RawImage>().texture = dices.ElementAt[0].texture;
}
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}