Hello,
I’m doing a simple board game in which each tile is a real life event. I would like to have a section where the current tile is displayed for the players to know what they have to do. To do this, I’ve put all of the images on my scene, and I want to set only the current one active. My plan is to put all the tiles in an array, and to use the tile number and the
gameObject.SetActive(true);
function to make them appear. my problem is that I have this error :
“NullReferenceException: Object reference not set to an instance of an object
CurrentTile.Update () (at Assets/CurrentTile.cs:203)”
I don’t know what I do wrong, and I can’t find good resources about my problem.
What can I do ?
Here’s my code, It’s long because I have to find all my games objects.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CurrentTile : MonoBehaviour
{
public static GameObject[] Tile = new GameObject[176];
public static GameObject ImagesTiles;
private static GameObject player1, player2, player3, player4, player5, player6;
// Start is called before the first frame update
void Start()
{
ImagesTiles = GameObject.Find("ImagesTiles");
ImagesTiles.gameObject.SetActive(false);
Tile[0] = GameObject.Find("Start");
Tile[1] = GameObject.Find("Shots");
Tile[2] = GameObject.Find("ActionVerite");
Tile[3] = GameObject.Find("ComplimentsF");
Tile[4] = GameObject.Find("TuPrefere");
Tile[5] = GameObject.Find("EpileRase");
Tile[6] = GameObject.Find("PierreFeuilleCiseaux");
Tile[7] = GameObject.Find("Habits");
Tile[8] = GameObject.Find("Voisins");
Tile[9] = GameObject.Find("Cartes");
Tile[10] = GameObject.Find("OnFire");
Tile[11] = GameObject.Find("BeauCorps");
Tile[12] = GameObject.Find("Photo");
Tile[13] = GameObject.Find("Dessine");
Tile[14] = GameObject.Find("LecheCou");
Tile[15] = GameObject.Find("PasMain");
Tile[16] = GameObject.Find("Soutif");
Tile[17] = GameObject.Find("PasRire");
Tile[18] = GameObject.Find("Back");
Tile[19] = GameObject.Find("SurLeCorps");
Tile[20] = GameObject.Find("Theme");
Tile[21] = GameObject.Find("Nourriture");
Tile[22] = GameObject.Find("Shots2");
Tile[23] = GameObject.Find("Masque");
Tile[24] = GameObject.Find("YeuxVerts");
Tile[25] = GameObject.Find("LapDance");
Tile[26] = GameObject.Find("PlusSexy");
Tile[27] = GameObject.Find("Fumeurs");
Tile[28] = GameObject.Find("Vite");
Tile[29] = GameObject.Find("Massage");
Tile[30] = GameObject.Find("Bouteille");
Tile[31] = GameObject.Find("Suçon");
Tile[32] = GameObject.Find("LePlusProche");
Tile[33] = GameObject.Find("Enleve");
Tile[34] = GameObject.Find("Kiss");
Tile[35] = GameObject.Find("Safe");
Tile[36] = GameObject.Find("MemeSexe");
Tile[37] = GameObject.Find("Suçon2");
Tile[38] = GameObject.Find("StripTease");
Tile[39] = GameObject.Find("PartageNourriture");
Tile[40] = GameObject.Find("TueKissMarie");
Tile[41] = GameObject.Find("Verite");
Tile[42] = GameObject.Find("LecheVentre");
Tile[43] = GameObject.Find("1ereFoisExperience");
Tile[44] = GameObject.Find("Avant183Gorgees");
Tile[45] = GameObject.Find("FantasmeSurQqnIci");
Tile[46] = GameObject.Find("Erotiques");
Tile[47] = GameObject.Find("ComplimentsH");
Tile[48] = GameObject.Find("Bouteille2");
Tile[49] = GameObject.Find("Voisins2");
Tile[50] = GameObject.Find("Action");
Tile[51] = GameObject.Find("CoupleIci");
Tile[52] = GameObject.Find("1erEtDernierKiss");
Tile[53] = GameObject.Find("Hommes");
Tile[54] = GameObject.Find("MemeSexe2");
Tile[55] = GameObject.Find("Twerk");
Tile[56] = GameObject.Find("Masque2");
Tile[57] = GameObject.Find("BeerPong2");
Tile[58] = GameObject.Find("Cm");
Tile[59] = GameObject.Find("LecheAlcoolSurVentre");
Tile[60] = GameObject.Find("Bouteille3");
Tile[61] = GameObject.Find("Suçon3");
Tile[62] = GameObject.Find("Cartes2");
Tile[63] = GameObject.Find("PierreFeuilleCiseaux2");
Tile[64] = GameObject.Find("StripTease2");
Tile[65] = GameObject.Find("BoisCmbDePBaisables");
Tile[66] = GameObject.Find("CoinFlip");
Tile[67] = GameObject.Find("Femmes");
Tile[68] = GameObject.Find("EchangeTshirts");
Tile[69] = GameObject.Find("Bois");
Tile[70] = GameObject.Find("Gauche");
Tile[71] = GameObject.Find("Voisins3");
Tile[72] = GameObject.Find("TonType");
Tile[73] = GameObject.Find("NbrDeFoisEnCouple");
Tile[74] = GameObject.Find("FaitChaud");
Tile[75] = GameObject.Find("KissMemeSexe");
Tile[76] = GameObject.Find("YeuxBleus");
Tile[77] = GameObject.Find("PasMains");
Tile[78] = GameObject.Find("7Minutes");
Tile[79] = GameObject.Find("Theme2");
Tile[80] = GameObject.Find("EchangeVerres");
Tile[81] = GameObject.Find("Shots3");
Tile[82] = GameObject.Find("FaitChaud2");
Tile[83] = GameObject.Find("KissGauche");
Tile[84] = GameObject.Find("PlusSexy");
Tile[85] = GameObject.Find("Massage");
Tile[86] = GameObject.Find("BisouLangoureuxCou");
Tile[87] = GameObject.Find("Touche");
Tile[88] = GameObject.Find("DernierBuveur");
Tile[89] = GameObject.Find("Couleur");
Tile[90] = GameObject.Find("MeilleureChosePhysique");
Tile[91] = GameObject.Find("Avoue");
Tile[92] = GameObject.Find("Masque3");
Tile[93] = GameObject.Find("Theme3");
Tile[94] = GameObject.Find("BeerPong2");
Tile[95] = GameObject.Find("CanalBoueux");
Tile[96] = GameObject.Find("Cupidon");
Tile[97] = GameObject.Find("Action");
Tile[98] = GameObject.Find("Shots4");
Tile[99] = GameObject.Find("Suçon4");
Tile[100] = GameObject.Find("Glaçon");
Tile[101] = GameObject.Find("Vite");
Tile[102] = GameObject.Find("ShotDroite");
Tile[103] = GameObject.Find("KissEverybody");
Tile[104] = GameObject.Find("Back2");
Tile[105] = GameObject.Find("Safe2");
Tile[106] = GameObject.Find("Erotiques2");
Tile[107] = GameObject.Find("Twerk2");
Tile[108] = GameObject.Find("KissDroite");
Tile[109] = GameObject.Find("LecheCou2");
Tile[110] = GameObject.Find("PlusJeunePlusVieux");
Tile[111] = GameObject.Find("YeuxBruns");
Tile[112] = GameObject.Find("Bouteille4");
Tile[113] = GameObject.Find("Cartes3");
Tile[114] = GameObject.Find("BoireQui");
Tile[115] = GameObject.Find("7Minutes2");
Tile[116] = GameObject.Find("Back3");
Tile[117] = GameObject.Find("LecheVentre2");
Tile[118] = GameObject.Find("EchangeTshirts2");
Tile[119] = GameObject.Find("PasRire2");
Tile[120] = GameObject.Find("Cm2");
Tile[121] = GameObject.Find("Kiss2");
Tile[122] = GameObject.Find("Cambre");
Tile[123] = GameObject.Find("FaitFroid");
Tile[124] = GameObject.Find("Plus183Gorgees2");
Tile[125] = GameObject.Find("AutreSexe");
Tile[126] = GameObject.Find("BeerPong3");
Tile[127] = GameObject.Find("FaitChaud");
Tile[128] = GameObject.Find("EnleveUnHabitAQqn");
Tile[129] = GameObject.Find("Vierges");
Tile[130] = GameObject.Find("MasturbeMoins2Jours");
Tile[131] = GameObject.Find("LapDance2");
Tile[132] = GameObject.Find("Masque4");
Tile[133] = GameObject.Find("AvalerCuni");
Tile[134] = GameObject.Find("Bouteille5");
Tile[135] = GameObject.Find("LePlusGrosRateau");
Tile[136] = GameObject.Find("Kiss3");
Tile[137] = GameObject.Find("EchangeVerres2");
Tile[138] = GameObject.Find("Suçon5");
Tile[139] = GameObject.Find("Cupidon2");
Tile[140] = GameObject.Find("Beuh");
Tile[141] = GameObject.Find("Soutif2");
Tile[142] = GameObject.Find("SuçonPourTous");
Tile[143] = GameObject.Find("StripTease3");
Tile[144] = GameObject.Find("MakeUpTime");
Tile[145] = GameObject.Find("AgeMoyen");
Tile[146] = GameObject.Find("DejaCompare");
Tile[147] = GameObject.Find("Amoureux");
Tile[148] = GameObject.Find("LapDance3");
Tile[149] = GameObject.Find("Glaçon2");
Tile[150] = GameObject.Find("MemeSexe4");
Tile[151] = GameObject.Find("Notifs");
Tile[152] = GameObject.Find("TueKissMarie2");
Tile[153] = GameObject.Find("Droite");
Tile[154] = GameObject.Find("Crush");
Tile[155] = GameObject.Find("EndroitFantasme");
Tile[156] = GameObject.Find("EchangeBas");
Tile[157] = GameObject.Find("Couleur2");
Tile[158] = GameObject.Find("LecheCou3");
Tile[159] = GameObject.Find("LeMoinsBu");
Tile[160] = GameObject.Find("PasMains2");
Tile[161] = GameObject.Find("Masque5");
Tile[162] = GameObject.Find("Back4");
Tile[163] = GameObject.Find("Debout");
Tile[164] = GameObject.Find("Karaoke");
Tile[165] = GameObject.Find("LaPlusGrosse");
Tile[166] = GameObject.Find("Photo2");
Tile[167] = GameObject.Find("NbrDePersonnes");
Tile[168] = GameObject.Find("EchangeDeTenues");
Tile[169] = GameObject.Find("Nudes");
Tile[170] = GameObject.Find("Dessine2");
Tile[171] = GameObject.Find("LePlusAttirante");
Tile[172] = GameObject.Find("Vite");
Tile[173] = GameObject.Find("Massage");
Tile[174] = GameObject.Find("FaitTresChaud");
Tile[175] = GameObject.Find("End");
}
// Update is called once per frame
void Update() {
if (GameControl.PlayerToTile == 1){
Tile[2].gameObject.SetActive(false);
}
if (GameControl.PlayerToTile == 2){
ImagesTiles.gameObject.SetActive(true);
}
}
}
Thanks for any help !