Public Group

This topic is 1321 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hello, this is my first post on these forums but I just finished my first little text based game in C# for Unity. Just wonder if I could maybe get some feedback and possibly some pointers. I'm learning through a Udemy course and they provided a hosting service so you can test the game out in the web player here. In their example they used a finite state machine. Which I realize I could have done, but since I paused the video early and went off on my own I took a different approach, using integers to detect whether a player had obtained an object or not and if they obtained the object then call this state. (I think I'm describing that right? If not let me know.)
Anyway thanks for taking the time.

-WildPants

Also if you wish to see the link it is http://gamebucket.io/game/2219c8f1-6259-46e6-8b80-2e56cf1549e6

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class TextController : MonoBehaviour {

public Text text;

private enum States {spawn, key_0, lever_0, cart_0, key_1, lever_1, cart_1, wife, lever_2};
private States myState;

int key;
int lever;
int key_lock;

// Use this for initialization
void Start () {
myState = States.spawn;

}

// Update is called once per frame
void Update () {
print (myState);
if 		(myState == States.spawn)		{state_spawn();}
else if (myState == States.key_0)		{state_key_0();}
else if (myState == States.key_1)		{state_key_1();}
else if (myState == States.cart_0)		{state_cart_0();}
else if (myState == States.cart_1)		{state_cart_1();}
else if (myState == States.lever_0)		{state_lever_0();}
else if (myState == States.lever_1)		{state_lever_1();}
else if (myState == States.lever_2)		{state_lever_2();}
else if (myState == States.wife)		{state_wife ();}

}

// When at start location.
void state_spawn () {
text.text = "You are in Hell, you've payed the toll to cross Styx and now you're here to find your wife..." +
"you just hope there's something left of her to find. " +
"There are three corridors: one leading left where you can clearly " +
"see a very old door and a very small object shines at its foot. " +
"Then there's a corridor to the right, lit by candles dripping red wax. " +
"Finally in front of you sits a passenger cart on a very old and " +
"rusted track that seemingly goes on forever down a dark and musty corridor. " +
"You can clearly see a mechanism that will release the cart and send it on its way " +
"down the corridor but without a lever it's useless.\n\n" +
"Press L to go down the left corridor.\n" +
"Press C to inspect the cart.\n" +
"Press R to go down the right corridor.";
if (Input.GetKeyDown(KeyCode.L)) {
myState = States.key_0;
state_key_0 ();
}
else if (Input.GetKeyDown(KeyCode.C)) {
myState = States.cart_0;
state_cart_0 ();
}
else if (Input.GetKeyDown(KeyCode.R)) {
myState = States.lever_0;
state_lever_0 ();
}
}

//Left Corridor, Key Pickup
void state_key_0 () {
if (key == 0){
text.text = "You venture down the left corridor toward the very old door to find that it is rusted shut. " +
"However, at the foot of the door you see a small object shining in a pile of discarded rotten flesh.\n\n" +
"Press P to pick up the object.\n" +
"Press B to go Back to where you started.";
} 	if (Input.GetKeyDown(KeyCode.P)) {
key = 1;
myState = States.key_1;
state_key_1 ();
}
else if (Input.GetKeyDown(KeyCode.B)) {
myState = States.spawn;
state_spawn ();
}

else if (key > 0){
text.text = "You venture down the left corridor toward the very old door to find that it is still rusted shut.\n\n" +
"Press B to go Back to where you started.";
}	if (Input.GetKeyDown(KeyCode.B)) {
myState = States.spawn;
state_spawn ();
}

}

//When Key is obtained in Left Corridor
void state_key_1 () {
text.text = "Congratulations you found an Old Rotten Key. You wonder what it opens as " +
"you slide it into your pocket.\n\n" +
"Press B to go Back to where you started.";
if (Input.GetKeyDown(KeyCode.B)) {
myState = States.spawn;
state_spawn ();
}
}

//When Cart is Chosen, check if lever is 0 or greater than 0.
void state_cart_0 () {
if (lever == 0){
text.text = "You approach the passenger cart, and see the broken mechanism to its left. " +
"You know that this piece of shit is useless without a lever for that mechanism.\n\n" +
"Press B to turn back and start looking for a way to find that lever.";
} 	if (Input.GetKeyDown(KeyCode.B)) {
myState = States.spawn;
state_spawn ();
}
else if (lever > 0){
text.text = "You approach the passenger cart, and see the broken mechanism to its left. " +
"You know that this piece of shit is useless without a lever for that mechanism.\n\n" +
"Press W to wedge the lever into the mechanism.\n" +
"Press B to go back where you started.";
}	if(Input.GetKeyDown(KeyCode.W)) {
myState = States.cart_1;
state_cart_1 ();
}
else if(Input.GetKeyDown(KeyCode.B)) {
myState = States.spawn;
state_spawn ();
}

}

//When Cart is Chosen and lever is greater than 0.
void state_cart_1 () {

text.text = "Nice, finally got that damned thing wedged into the Mechanism.\n" +
"Now lets get moving!\n\n" +
"Press P to Pull the lever and jump on and find your wife.";
if (Input.GetKeyDown(KeyCode.P)) {
myState = States.wife;
state_wife ();
}

}

//When Right Corridor is Chosen but key = 0
void state_lever_0 () {
if (key == 0){
text.text = "You walk viligantly down the Right Corridor as you watch the wax drip slowly from the candles. " +
"Suddenly chills run down your spine as you realize those candles aren't dripping wax at all, no. " +
"Son-of-a-bitch, it's blood. \n" +
"You come to the end of the corridor to find a cage clearly containing the lever. " +
"You try to open it only to find that it is kept secure by a padlock made of bone and you " +
"think to yourself, how the hell am I going to open this thing?\n\n" +
"Press B to turn back and start looking for a key to get to the lever";
}	if (Input.GetKeyDown(KeyCode.B)) {
myState = States.spawn;
state_spawn();

} else if (key > 0){
text.text = "You walk viligantly down the Right Corridor as you watch the wax drip slowly from the candles. " +
"Suddenly chills run down your spine as you realize those candles aren't dripping wax at all, no. " +
"Son-of-a-bitch, it's blood... " +
"You come to the end of the corridor to find a cage clearly containing the lever. " +
"You try to open it only to find that it is kept secure by a padlock made of bone and you " +
"think to yourself, how the hell am I going to open this thing?\n\n" +
"Press K to use the Old Rotten key.\n" +
"Press B to go back to where you started.";
} if (Input.GetKeyDown(KeyCode.K)) {
key_lock = 1;
myState = States.lever_1;
state_lever_1();
} else if (Input.GetKeyDown(KeyCode.B)) {
myState = States.spawn;
state_spawn();

} else if (lever > 0){
text.text = "You walk viligantly down the Right Corridor as you watch the blood drip slowly from the candles. " +
"It doesn't seem to startle you as much as it did the first time around. " +
"Finally you reach the now empty cage and stare at the padlock on the floor all while you wonder why the hell you came back this way.\n\n" +
"Press B to go back to where you started";
} if (Input.GetKeyDown(KeyCode.B)) {
myState = States.spawn;
state_spawn ();

} else if (key_lock > 0){
text.text = "You return to the cage, luckily the lever is still there.\n\n" +
"Press T to take the lever,\n" +
"Press B to go back to where you started.";
if (Input.GetKeyDown(KeyCode.T)) {
lever = 1;
key_lock = 0;
myState = States.lever_2;
state_lever_2 ();
} else if (Input.GetKeyDown(KeyCode.B)){
myState = States.spawn;
state_spawn();
}
}
}

//When Lever Cage is opened and the object is attainable
void state_lever_1 () {

text.text = "You shimmy the key in the lock and feel it come loose. The padlock falls to the ground " +
"and the door to the cage swings open. The lever is within reach.\n\n" +
"Press T to take the lever.\n" +
"Press B to go back to where you started.";
if (Input.GetKeyDown(KeyCode.T)) {
lever = 1;
myState = States.lever_2;
state_lever_2 ();
} else if (Input.GetKeyDown(KeyCode.B)){
myState = States.spawn;
state_spawn();
}

}

//When Lever is attained
void state_lever_2 () {

text.text = "Congratulations you got the Rusty Old Lever \n\n" +
"Press B to go back to where you started.";
if (Input.GetKeyDown(KeyCode.B)) {
myState = States.spawn;
state_spawn ();

}

}
void state_wife () {

text.text = "Congratulations, you eventually found your wife and got out of Hell.";

}

}


1. 1
Rutin
29
2. 2
3. 3
4. 4
5. 5

• 13
• 13
• 11
• 10
• 13
• Forum Statistics

• Total Topics
632960
• Total Posts
3009472
• Who's Online (See full list)

There are no registered users currently online

×