my game's features didn't work after build

Hai am new to unity. I wanted to try out my game. It is working fine withing the Unity engine but once i completed the built (PC and Mac standalone) and tried playing with the exe file, most of the features aren’t working! like, the game shud be over when the player touches with the collider but it didnt work. But they are still fine in unity. i think there’s something wrong with my script but im really confuse how to fix it… please teach me how to fix it

i get this error below in the output_log:

NullReferenceException: Object reference not set to an instance of an object
at menuscript.Start () [0x00000] in :0

(Filename: Line: -1)

clicked on Review

(Filename: C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 64)

clicked on Review

you have an error in “menuscript” somewhere in the start function… look there (or if you want help with that, post your code from that script here in [ code][ /code] tags)

1 Like

Code tags.

What you posted just now is not readable. And people are (rightfully) skeptical of downloading random files off the internet, although the paranoia about that on this forum is a bit extreme.

1 Like
using UnityEngine.UI;
using System.Collections;

public class menuscript : MonoBehaviour {

    public Canvas quitMenu;
    public Button startText;
    public Button exitText;

    // Use this for initialization
    void Start ()
    {
        quitMenu = quitMenu.GetComponent<Canvas> ();
        startText = startText.GetComponent<Button> ();
        exitText = exitText.GetComponent<Button> ();
        quitMenu.enabled = false;
    }

    public void ExitPress()
    {
        quitMenu.enabled = true;
        startText.enabled = false;
        exitText.enabled = false;
    }

    public void NoPress()
    {
        quitMenu.enabled = false;
        startText.enabled = true;
        exitText.enabled = true;
    }

    public void StartLevel()
    {
        Application.LoadLevel ("GamePlay");
    }

    public void ExitGame()
    {
        Application.Quit ();
    }

    public void Scene()
    {
        Application.LoadLevel ("start menu");
    }


}

thx for the kind help

There’s something very wrong in your Start method:

quitMenu = quitMenu.GetComponent<Canvas> ();
startText = startText.GetComponent<Button> ();
exitText = exitText.GetComponent<Button> ();

You’re getting the components from themselves. That makes no sense. If you have assigned quitMenu, startText and exitText in the inspector, those calls are all doing nothing. If you haven’t assigned them in the menu, those calls will throw exceptions. What are you trying to do?

1 Like

hai this script im using is for my main menu…and actually i just copied the code from a tutorial in youtube
and the main menu is functioning well

here is the tutorial link:
https://www.youtube.com/watch?v=pT4uca2bSgc

skip to minute 15:34 to direct to the script part

using UnityEngine.UI;
using System.Collections;

where is

using UnityEngine;

?? did it get missed off in the copy/paste?

The tutorial’s Start code is absurd - as I said, it either does nothing, or crashes. The only line there that makes sense is the last one, which deactivates the quit menu.

The code’s also what’s causing the exceptions that’s crashing your game, because you haven’t assigned either quitMenu, startText or exitText in the inspector.

after deleting those 3 lines which u mention the output log show these errors:
NullReferenceException: Object reference not set to an instance of an object
at menuscript.Start () [0x00000] in :0

(Filename: Line: -1)

clicked on Play

(Filename: C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 64)

UnityException: GameObject has undefined tag!
at (wrapper managed-to-native) UnityEngine.GameObject:get_tag ()

at playerController.OnCollisionEnter2D (UnityEngine.Collision2D coll) [0x00000] in :0

(Filename: Line: -1)

and in the unity it show these errors:
UnassignedReferenceException: The variable quitMenu of menuscript has not been assigned.
You probably need to assign the quitMenu variable of the menuscript script in the inspector.
menuscript.Start () (at Assets/TapNJump/Scripts/menuscript.cs:17)

im really sorry if i burden u much…but im really new with unity and ur help is really important to me :slight_smile:

yes…my bad

As I’ve already said, you haven’t assigned the quit menu in the inspector.

I urge you to go through some of the official, easier tutorials in the Lean section (check on the top of the web page!). They’re pretty good, gets you started on Unity, and is written by somebody competent. We can help you, but your problems here are very basic, and you’ll be saving yourself a lot of waiting for answers if you spend more time on those tutorials.

1 Like