1
\$\begingroup\$

I uploaded the levelLoader file to the gameobject. Still, when I drag the script file onClick Event, the no function is null. Why? Can anybody help me?

No Function

C# code:

using UnityEngine;
using System.Collections;

public class LevelLoader : MonoBehaviour {

    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame


    public void LoadLevel(int a)
    {

        Application.LoadLevel(a);
    }

    public void Quit()
    {

        Application.Quit();
    }
}

Correct me where I am wrong. I am following this racing car game tutorial. At 7:58 he added this event. Please help me!!!

\$\endgroup\$
4
  • \$\begingroup\$ Did you drag the script directly from the project folder? You might need to have the script added to an actual game object in the scene because the function you are trying to access is not static, therefore it needs an instance of an object. \$\endgroup\$ Dec 6 '16 at 17:26
  • \$\begingroup\$ Yes, I directly dragged the script file to the scene. \$\endgroup\$
    – Warda
    Dec 6 '16 at 17:29
  • \$\begingroup\$ @Sys_Admin_Luddite I couldn't get you how to add the script file to an actual gameobject? I am newbie, so am little bit confused. \$\endgroup\$
    – Warda
    Dec 6 '16 at 17:31
  • \$\begingroup\$ You musn't drag & drop the script itself, but the object holding the script. To do so, create a new Empty gameobject in your scene, and drag & drop the file (from Project tab) to the empty game object in the Hierarchy tab. \$\endgroup\$
    – Hellium
    Dec 6 '16 at 17:48
3
\$\begingroup\$

You need to add the LevelLoader script to the LevelLoader object in the hierarchy panel. Then drag the entire LevelLoader object (not script) from the hierarchy panel to the OnClick selected object.

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 .