Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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 () {

    }
}
share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.