Hello community,
I have been creating my first Unity game for android after coming over from the standard SDK. I am by no means fluent in C# but i have had a fair amount of experience with Java. But back to the task at hand; i am creating an app with a grid of 9 buttons every time one of the buttons is clicked a random number is generated(this is not displayed to the user), When that number is equal to a certain number it changes the image of the button that was clicked.
this is what i have so far on the script relating to this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class BF : MonoBehaviour {
private int rand;
public Sprite Goldlayer;
public void OnButtonClick()
{
var gotit = EventSystem.current.currentSelectedGameObject;
rand = Random.Range(1, 10);
if (gotit != null)
{
Debug.Log(gotit.name);
if (rand == 1)
{
gotit.image.sprite = Goldlayer;
}else{}
}else {}
}
}
So I have attached this script to the camera so when any of the buttons are clicked it will know which one(this is contained in gotit) is clicked. The issue i am having is that i can not change the image of the clicked button because it doesn’t have an “image definition”. I dont know why it doesn’t, i would of thought it would be like any other game object.
If you have any ideas or suggestions i would greatly appreciate it.
Kind and thankful Regards.
Thanks so much man really helpful and thanks for taking the time with my question. Hope you have a good one.
– Vacler