- Home /
Question by
Dariy3 · Apr 15, 2017 at 12:13 PM ·
scene-loadingif-statementsinputfieldobject reference
NullReferenceException: Object reference not set to an instance of an object
Hi everyone and i need your help. I don't understand what i need to do. Can you look at my script and help me please.
using System.Collections;
using UnityEngine;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class exam : MonoBehaviour {
public string a;
public InputField imf;
public void Start(){
string a = imf.text;
}
public void OnClickStart()
{
if (a == "Na") {
SceneManager.LoadScene (0);
}
}
}
Comment
Answer by Ryuuguu · Apr 15, 2017 at 01:09 PM
If the exception is pointing to like 11 then you have not set imf in the inspector.
in the inspector in Unity do you have a object linked to the field imf? if you do not then that is your problem. Your script is fine. The problem is that imf is not assigned in your scene.
Okey i understand that i should rename something, but what? Can you tell me please
безымянныи.png
(121.4 kB)
Answer by putlucky · Apr 18, 2017 at 04:06 PM
Ryuuguu is probably right, but in future you should post the entire exception, which will tell you the line number where the error occurs.
Your answer
