using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
using System;
public class TextController : MonoBehaviour {
private bool bStart = true;
private string instructions = "You have the following commands at your disposal:
" +
"* First Verse, Second Verse
" +
"* First Chorus, Second Chorus, Third Chorus
" +
“* First Bridge, Second Bridge”;
private Text text;
private LyricList lineList = new LyricList();
private InputField inputField;
private string newState;
String s = null;
// Use this for initialization
void Start () {
// Get the text child object from the Canvas
text = gameObject.GetComponent<Text> ();
// Get the input field child object from the Canvas
inputField = gameObject.GetComponentInChildren<InputField> ();
//CreateAssetMenuAttribute on Lyric List
lineList.CreateList ();
text.text = ("Please reassemble the song lyrics!
" + instructions + "
Start guessing to begin!
");
}
void Update(){
// Check for input from the input field
if (Input.GetKeyDown (KeyCode.Return)) {
if (inputField.text != "") { // .trim
newState = inputField.text;
newState = newState.ToLower();
lineList.LyricSwitch (newState);
inputField.text = "";
// If we've entered something bStart needs to be switched to false to print the lyrics
if(bStart){
bStart = false;
}
}
}
// We've had text entered into the input field, now show the correct lyrics
else if (!bStart) {
foreach (Lyric line in lineList.lLyrics) {
if (line.getState () == lineList.getCurrentState ()) {
text.text += line.getLyric ();
text.text += "
" + instructions + "
";
}
}
}
// Make sure to set the Input Field to Active
//inputField.ActivateInputField ();
}
}
SCRIPT 2
public class LyricList {
public List<Lyric> lLyrics = new List<Lyric>();
private Helpers.STATE curState = Helpers.STATE.chorus1;
private string[] aCommands = {"first chorus", "second chorus", "third chorus", "first bridge", "second bridge", "first verse", "second verse", "third verse"};
public string getCurrentState(){
return curState.ToString();
}
// Use Present Lyric to the
public void LyricSwitch (string newState) {
for (int i = 0; i < aCommands.Length; i++) {
if(string.Compare(newState, aCommands*, true) == 0)*
-
break;* -
else if(i == aCommands.Length-1)* -
newState = "";* -
}* -
switch (newState) {* -
case "first chorus":* -
curState = Helpers.STATE.chorus1;* -
break;* -
case "second chorus":* -
curState = Helpers.STATE.chorus2;* -
break;* -
case "third chorus":* -
curState = Helpers.STATE.chorus3;* -
break;* -
case "first bridge":* -
curState = Helpers.STATE.bridge1;* -
break;* -
case "second bridge":* -
curState = Helpers.STATE.bridge2;* -
break;* -
case "first verse":* -
curState = Helpers.STATE.verse1;* -
break;* -
case "second verse":* -
curState = Helpers.STATE.verse2;* -
break;* -
case "third verse":* -
curState = Helpers.STATE.verse3;* -
break;* -
default:* -
curState = Helpers.STATE.notachoice;* -
break;* -
}* -
}*
-
public void CreateList () {*
-
// Chorus lyrics* -
lLyrics.Add ( new Lyric("chorus1", "Never gonna give you up
"*
-
+ "Never gonna let you down/n "));* -
lLyrics.Add ( new Lyric("chorus2", "Never gonna run around and desert you
"*
-
+ "Never gonna make you cry
"));*
-
lLyrics.Add ( new Lyric("chorus3", "Never gonna say goodbye
"*
-
+ "Never gonna tell a lie and hurt you
"));*
-
// door scripts* -
lLyrics.Add ( new Lyric("bridge1", "I just wanna tell you how I'm feeling
"*
-
+ "Gotta make you understand
"));*
-
lLyrics.Add ( new Lyric("bridge2", "And if you ask me how I'm feeling
"*
-
+ "Don't tell me you're too blind to see
"));*
-
// bowl scripts* -
lLyrics.Add ( new Lyric("verse1", "We're no strangers to love
"*
-
+ "You know the rules and so do I
"*
-
+ "A full commitment's what I'm thinking of
"*
-
+ "You wouldn't get this from any other guy
"));*
-
lLyrics.Add ( new Lyric("verse2", "We've known each other for so long
"*
-
+ "Your heart's been aching, but
"*
-
+ "You're too shy to say it
"*
-
+ "Inside, we both know what's been going on
"*
-
+ "We know the game and we're gonna play it
"));*
-
lLyrics.Add ( new Lyric("notachoice", "That isn't an option."));* - }*
}
SCRIPT 3
public class Lyric {
-
private Helpers.STATE eState;*
-
private string sLyric;*
-
public Lyric(string state, string script){*
-
eState = Helpers.ParseEnum<Helpers.STATE>(state);* -
sLyric = script;* -
}*
-
public string getLyric(){*
-
return sLyric;* -
}*
-
public string getState(){*
-
return eState.ToString();* -
}*
-
public void setLyric(string lyric){*
-
sLyric = lyric;* -
}*
-
public void setState(string state){*
-
eState = Helpers.ParseEnum<Helpers.STATE>(state);* -
}*
-
public bool compareStatetoString(string compare){*
-
if (eState == Helpers.ParseEnum<Helpers.STATE> (compare))* -
return true;* -
else* -
return false;* -
}*
}
SCRIPT 4
using UnityEngine;
using System.Collections;
public class Helpers {
-
public enum STATE{chorus1, chorus2, chorus3, bridge1, bridge2, verse1, verse2, verse3, notachoice};*
-
public static T ParseEnum(string value)*
-
{*
-
return (T) System.Enum.Parse(typeof(T), value, true);* -
}*
}
Null ref is on line 40 of the first script… it says an object is not set to an instance… I can not find the object and its really bugging me out. Any help?