Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

Null error.

$
0
0
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:\n" + "*\tFirst Verse, Second Verse\n" + "*\tFirst Chorus, Second Chorus, Third Chorus\n" + "*\tFirst 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 (); // Get the input field child object from the Canvas inputField = gameObject.GetComponentInChildren (); //CreateAssetMenuAttribute on Lyric List lineList.CreateList (); text.text = ("Please reassemble the song lyrics!\n" + instructions + "\n\nStart guessing to begin!\n\n"); } 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 += "\n\n" + instructions + "\n"; } } } // Make sure to set the Input Field to Active //inputField.ActivateInputField (); } } SCRIPT 2 public class LyricList { public List lLyrics = new List(); 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[i], 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\n" + "Never gonna let you down/n ")); lLyrics.Add ( new Lyric("chorus2", "Never gonna run around and desert you\n" + "Never gonna make you cry\n")); lLyrics.Add ( new Lyric("chorus3", "Never gonna say goodbye\n" + "Never gonna tell a lie and hurt you\n\n")); // door scripts lLyrics.Add ( new Lyric("bridge1", "I just wanna tell you how I'm feeling\n" + "Gotta make you understand\n\n")); lLyrics.Add ( new Lyric("bridge2", "And if you ask me how I'm feeling\n" + "Don't tell me you're too blind to see\n\n")); // bowl scripts lLyrics.Add ( new Lyric("verse1", "We're no strangers to love\n" + "You know the rules and so do I\n" + "A full commitment's what I'm thinking of\n" + "You wouldn't get this from any other guy\n")); lLyrics.Add ( new Lyric("verse2", "We've known each other for so long\n" + "Your heart's been aching, but\n" + "You're too shy to say it\n" + "Inside, we both know what's been going on\n" + "We know the game and we're gonna play it\n")); 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(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(state); } public bool compareStatetoString(string compare){ if (eState == Helpers.ParseEnum (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?

Viewing all articles
Browse latest Browse all 2891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>