0
\$\begingroup\$

I am making a car game in unity 5.0.4f1. I am facing two snags.

  1. While installing 3.5 net framework, it gives an error. I searched, it took my 2hrs and problem couldn't solve. Then, I reinstalled Unity. For this snag, what is the best solution in a way I won't waste my time anymore?
  2. On the other hand, when I added a C# script using VS community 2015, after dragging the script on the click event, No function doesn't show me the script name in the drop down menu. I'm following this tutorial, tutorial link. At 7:58 he added the script in on function. For me, it is not working.

Game View

using UnityEngine;
using System.Collections;

public class LevelLoader : MonoBehaviour {

    GameObject menu_Canvas;
    GameObject settings_Canvas;

    void Start () {

        menu_Canvas = GameObject.Find ("MainMenu_Canvas");
        settings_Canvas = GameObject.Find ("Settings_Canvas");

        settings_Canvas.SetActive (false);
        menu_Canvas.SetActive (true);
    }

    public void LoadLevel (int a) {

        Application.LoadLevel (a);
    }

    public void Quit () {

        Application.Quit ();
    }

    public void loadMenu () {

        menu_Canvas.SetActive (true);
        settings_Canvas.SetActive (false);
    }

    public void loadSettings () {

        menu_Canvas.SetActive (false);
        settings_Canvas.SetActive (true);
    }
}

Please help, as I have been trapped in the problem since few days.

\$\endgroup\$
5
  • \$\begingroup\$ please share your code.do you place script instead of gameObject to OnClick() field? so you should attach it to gameObject so place it there. do you use public access modifier in your code? \$\endgroup\$ Commented Dec 6, 2016 at 10:16
  • \$\begingroup\$ is LevelLoader added to a gameObject? \$\endgroup\$
    – Uri Popov
    Commented Dec 6, 2016 at 10:17
  • \$\begingroup\$ @smkplus I updated the question... \$\endgroup\$
    – Warda
    Commented Dec 6, 2016 at 10:43
  • \$\begingroup\$ @UriPopov as you can see that I dropped the script file 'LevelLoader' below the Runtime in On Click event. \$\endgroup\$
    – Warda
    Commented Dec 6, 2016 at 10:48
  • \$\begingroup\$ I am a newbie for Unity. Can you elaborate what do you mean by LevelLoader added to a gameobject? \$\endgroup\$
    – Warda
    Commented Dec 6, 2016 at 10:49

1 Answer 1

0
\$\begingroup\$

Ok you seem to be directly dragging the script to the Onclick event. What you need to do is drag the script onto a game object that is in the scene. Then select that object in the event and then select the script component. Monobehaviours dont work if they are not on a game Object.enter image description here enter image description here

\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .