Sorry to keep flooding your inbox. I finally figured it out. Code below. ================================== usin…

Forum Archive Sorry to keep flooding your inbox. I finally figured it out. Code below. ================================== usin…

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #4776
    Arn Sweatman
    Participant

      Sorry to keep flooding your inbox. I finally figured it out. Code below.

      ==================================

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

      public class ExitScript : MonoBehaviour {

      public Text nameMe;

      void Start () {
      //nameMe = gameObject.GetComponent();
      //nameMe = GetComponent();
      nameMe.text = “Welcome to Scene 01”;
      }

      // Update is called once per frame
      void Update () {

      if(Input.GetKeyDown (KeyCode.Escape))
      {
      Application.LoadLevel (0);
      print (“Back to Main Page”);
      }

      else if(Input.GetKeyDown (KeyCode.G))
      {
      nameMe.text = “Howdy!”;

      }

      }

      }

      ============================================

      dunno how/why GetComponent was screwing things up. Oh well.

      LUV what you’re doing Jonathan! Big Thanks!!

      #23060
      Jonathan Gonzalez
      Participant

        I think I know what error you’re getting, or at least I see an error still present. In later versions of Unity 5 they stopped using “Application.LoadLevel()” and now use a “SceneManager”.

        So at the very top you need to use this namespace:
        using UnityEngine.SceneManagement;

        Then to load a scene you write:
        SceneManager.LoadScene(1);

        With GetComponent you need to specify what you’re getting. I assume the “text” elements in your script above was stripped int he comment but if not I’ll specify. A game object can have multiple components on them. 

        Sometimes this is not needed though as Unity will often do this for you in the background. Commonly used components will be cached for you like this in the background.

        #23061
        Arn Sweatman
        Participant

          I hate when they do that. =]

          Thanks for the feedback.

        Viewing 3 posts - 1 through 3 (of 3 total)
        • The topic ‘Sorry to keep flooding your inbox. I finally figured it out. Code below. ================================== usin…’ is closed to new replies.