copied game element not behaving correctly
I'm creating a game that involves betting. There are multiple tiles you can bet on so naturally I want them all to behave the same. I created the functionality of one tile so that it's fully functional.
When a red chip is selected, if the tile is clicked, a small red chip will appear on it with a number of how many were placed. This is the same for the other coloured chips, blue and green.
When i copy the tile (and all it's elements) even though the scripts are intact and it has the same instantiated objects etc etc (it's a literal exact clone), interactivity with it simply doesn't work.
they work off the same scripts and have the same drag and drop image fields (for the chips) on the inspector, but even though i've assigned different images to each tile, only the images on the original work, even when the second tile is clicked, only the original tiles images appear.
Will I have to duplicate the scripts for every tile? Or is there some easy workaround I'm overlooking? These are the relative scripts for reference: public class ImageClick : MonoBehaviour { //Image fields created for each chip on the tile public Image redchip; [SerializeField] //Image fields appear in inspector so chip images can be drag and dropped public Image bluechip; [SerializeField] public Image greenchip; [SerializeField]
//the public elements of the ChipChooser script are accessible in this script.
private ChipChooser myChipChooser;
//at initialisation the images visibility will be off
public void Start () {
redchip.enabled = false;
bluechip.enabled = false;
greenchip.enabled = false;
}
//when mouse click input is detected, the images visibility booelan will be reversed
public void OnMouseDown() {
if (myChipChooser.redclicked == true)
{
redchip.enabled = true; //visibility always true when clicked
ChipCounter.redChipNumber += 1;
}
if (myChipChooser.blueclicked == true)
{
bluechip.enabled = true;
ChipCounter.blueChipNumber += 1;
}
if (myChipChooser.greenclicked == true)
{
greenchip.enabled = true;
ChipCounter.greenChipNumber += 1;
}
}
}
and public class ChipChooser : MonoBehaviour { //public bools so they can be accessed throughout the program public bool redclicked; public bool blueclicked; public bool greenclicked;
//automatically false at start.
public void Start () {
redclicked = false;
blueclicked = false;
greenclicked = false;
}
//if the red chip is chosen...
public void RedChosen()
{
redclicked = true; //the red chips bool becomes active
blueclicked = false; //the others get reset to false
greenclicked = false;
Debug.Log(redclicked);
}
//The other functions perform the same duty as redChosen for different chips
public void BlueChosen()
{
blueclicked = true;
redclicked = false;
greenclicked = false;
Debug.Log(blueclicked);
}
public void GreenChosen()
{
greenclicked = true;
redclicked = false;
blueclicked = false;
Debug.Log(greenclicked);
}
}