using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
class StoryBlock
{
public string story;
public string option1Text;
public string option2Text;
public StoryBlock option1Block;
public StoryBlock option2Block;
public StoryBlock(string story, string option1Text = "", string option2Text = "", StoryBlock option1Block = null, StoryBlock option2Block = null)
{
this.story = story;
this.option1Text = option1Text;
this.option2Text = option2Text;
this.option2Block = option2Block;
this.option1Block = option1Block;
}
}
public class GameManager : MonoBehaviour
{
public Text mainText;
public Button option1;
public Button option2;
StoryBlock currentBlock;
static StoryBlock block41 = new StoryBlock("You gave them all the money and quitely went home. You discovered the quiter ending", "Play again", "Play again", block1, block1);
static StoryBlock block40 = new StoryBlock("You Bargained with them and settled on 80-20.You discovered the bargainer ending", "Play again", "Play again", block1, block1);
static StoryBlock block39 = new StoryBlock("You hide the body in the basement and went home. You discovered the Plain and Simple ending", "Play again", "Play again", block1, block1);
static StoryBlock block38 = new StoryBlock("You hide the body in the closet and were chilling out when the body came out of the closet and bite your neck. Youdiscovered the Zombie Apocclpse ending", "Play again", "Play again", block1, block1);
static StoryBlock block37 = new StoryBlock("You Offered them 50% money but they refused it", "Bargain", "Give all the money", block40, block41);
static StoryBlock block36 = new StoryBlock("You fought them but as expected you lose. You discovered the overconfident ending", "Play again", "Play again", block1, block1);
static StoryBlock block35 = new StoryBlock("You offered the Man to make you his partner and you both went off doing crimes together. You discovered the partnered criminal ending", "Play again", "Play again", block1, block1);
static StoryBlock block34 = new StoryBlock("You sucseded in killing him but died in the process. You discovered unprofesional killer ending", "Play again", "Play again", block1, block1);
static StoryBlock block33 = new StoryBlock("You shokyou head and told her to help find another shelter seeing that you are homeless she thought you were useless and killed you. You discovered the Homeless ending", "Play again", "Play again", block1, block1);
static StoryBlock block32 = new StoryBlock("You took her home and lived happily ever after.You discovered the Survivalist couplr ending", "Play again", "Play again", block1, block1);
static StoryBlock block31 = new StoryBlock("Shockingly she acepted it and promised to give protection if you provide her shelter", "Take her home", "Find another shelter", block32, block33);
static StoryBlock block30 = new StoryBlock("You tried to beg him but he killed you. You discoverd the too tired to code proper ending ending", "Play again", "Play again", block1, block1);
static StoryBlock block29 = new StoryBlock("You Tried to kill him but he killed you. You discoverd the too tired to code proper ending ending", "Play again", "Play again", block1, block1);
static StoryBlock block28 = new StoryBlock("You were tired and went off to sleep, someone came into your house and killed you. You didn't survive the Purge. You discovered the Sour dreams ending", "Play again", "Play again", block1, block1);
static StoryBlock block27 = new StoryBlock("You just spend the whole night playing games and surviving the purge. You discovered the Gamer ending", "Play again", "Play again", block1, block1);
static StoryBlock block26 = new StoryBlock("You just went to hide the body, Where will you hide it?", "Closet", "Basement", block38, block39);
static StoryBlock block25 = new StoryBlock("You were removing money from his pocket when suddenly a group of people came in front of you what well you do", "Fight them", "Give them 50% money", block36, block37);
static StoryBlock block24 = new StoryBlock("You sat on the couch and encountered another man, What will you do?", "Kill Him", "Become partner with Him",block34, block35);
static StoryBlock block23 = new StoryBlock("You knelled down before here locked into her eyes and asked for her hand", " ", "Continue", block31, block31);
static StoryBlock block22 = new StoryBlock("You tried to kill her but she killed you insted, You didn't survive the purge, You discovered the Not a Gentleman ending", "Play again", "Play again", block1, block1);
static StoryBlock block21 = new StoryBlock("You ran as fast as you can but you twisted your knee and you were killed. You didn't survive the Purge. You discovered the Ran till last ending", "Play again", "Play again", block1, block1);
static StoryBlock block20 = new StoryBlock("You pulled of a knife and killed him and moved forward and encountered another man, What will you do?", "Kill Him", "Beg for life", block29, block30);
static StoryBlock block19 = new StoryBlock("You kneeled down before him and begged him for life. You survived the purge. You discovered the Begged for life ending", "Play again", "Play again", block1, block1);
static StoryBlock block18 = new StoryBlock("You went in the kitchen to take a knife to kill him, but before you could do anything he killed you, You didn't survive the purge. You discovered the Too confident ending", "Play again", "Play again", block1, block1);
static StoryBlock block17 = new StoryBlock("You just let the body be and went into kitchen to eat something now what are you planing to do", "Play Games", "Go to Sleep", block27, block28);
static StoryBlock block16 = new StoryBlock("You decided to hide the body you went down to take the body and you saw money in his pocket should you take it", "Take the money", "Leave the money", block25, block26);
static StoryBlock block15 = new StoryBlock("You kneled before hin and ofered all your belongigs he accepted it and leved", " ", "Continue", block24, block24);
static StoryBlock block14 = new StoryBlock("You removed a knife from your pocket and held it onto his neck, you took all his belongings and killed him", " ", "Continue", block24, block24);
static StoryBlock block13 = new StoryBlock("You just left the stuff be and left the house, while you were roaming you encountered a girl what will you do?", "Kill Her", "Propose Her", block22, block23);
static StoryBlock block12 = new StoryBlock("You took some important stuff with you and set off. While you were moving you encountered a man", "Kill Him", "Run", block20, block21);
static StoryBlock block11 = new StoryBlock("You are too confident of yourself and just sat playing games. The man entered the room and came to kill you", "Kill Him", "Beg for Life", block18, block19);
static StoryBlock block10 = new StoryBlock("You went in the kitchen and grabed the knife you went towards the window and cut his hand off he fell and died Would you?", "Hind the body", "Leave the Body", block16, block17);
static StoryBlock block9 = new StoryBlock("You are too confident of yourself so you stayed in the house, And a man attacked you what will you do?", "Kill Him", "Bribe Him", block14, block15);
static StoryBlock block8 = new StoryBlock("You thought it was too risky to stay in the house so you left the house are you going to take anything with you", "Take Stuff", "Leave Stuff", block12, block13);
static StoryBlock block7 = new StoryBlock("You went to sleep and someone came into your house and killed you in sleep. You did't survive the Purge. You discovered the Dead Drowsy ending", "Play Again", "Play Again", block1, block1);
static StoryBlock block6 = new StoryBlock("You were playing games in your house when suddenly you heard a bang on the window you went and saw that a man is trying to enter the house", "Kill the Man", "Just play games", block10, block11);
static StoryBlock block5 = new StoryBlock("You were so confident on yourself that you leave your house open but you know that someone would target you so what will you do", "Leave your house", "Stay in House", block8, block9);
static StoryBlock block4 = new StoryBlock("You started to console your house you finished before the purge started now what will you do whole night", "Play Games", "Go to sleep", block6, block7);
static StoryBlock block3 = new StoryBlock("You decided not to participate in the purge.But you are not Safe, You need to ensure that you are safe", "Console your house", "Leave the house Open", block4, block5);
static StoryBlock block2 = new StoryBlock("Yet to made", "Go Back", "Go Back", block1, block1);
static StoryBlock block1 = new StoryBlock("You walked in home as usual and sat on couch to here the news", "Participate", "Don't Participate", block2, block3);
void Start()
{
DisplayBlock(block1);
}
void DisplayBlock(StoryBlock block)
{
mainText.text = block.story;
option1.GetComponent<Text>().text = block.option1Text;
option2.GetComponent<Text>().text = block.option2Text;
currentBlock = block;
}
public void Button1Clicked()
{
DisplayBlock(currentBlock.option1Block);
}
public void Button2Clicked()
{
DisplayBlock(currentBlock.option2Block);
}
}
Can anyone help me pls.
I’m not sure what you expect us to help you with.
If line 83 has a null error, then add Debug.Log messages to print out the possible null values.
option1
GetComponet()
block
block.option1Text
Those appear to be your possible null values.
Debug.Log("option1 " + option1); //If you see null with this, then option1 is null.
Default Button prefab does not have a Text component on the main object, it is in the child object.
So you need to use GetComponentInChildren.
The answer is always the same… ALWAYS. It is the single most common error ever.
Don’t waste your life spinning around and round on this error. Instead, learn how to fix it fast… it’s EASY!!
Some notes on how to fix a NullReferenceException error in Unity3D
- also known as: Unassigned Reference Exception
- also known as: Missing Reference Exception
- also known as: Object reference not set to an instance of an object
The basic steps outlined above are:
- Identify what is null
- Identify why it is null
- Fix that.
Expect to see this error a LOT. It’s easily the most common thing to do when working. Learn how to fix it rapidly. It’s easy. See the above link for more tips.
This is the kind of mindset and thinking process you need to bring to this problem:
https://discussions.unity.com/t/814091/4
Step by step, break it down, find the problem.