- Home /
Script on 3d model gives me NullReferenceException
Hi, I've but using my script on a cube which served until now as a gun for my first person controller. The problem is, I've downloaded a 3d model, put it as the child of the cube, deactivated the script on the cube, and put it on my 3d gun model but now it doesn't work. On my cube it did. I get a NullReferenceException : Object reference not set to an instance of an object. But I see in the inspector my object (first person controller) is referenced to. I've tried to change the object referenced to but it doesn't work better. Thanks for your help!
public class RenderAspirateur : MonoBehaviour {
public GameObject autreobjet;
FPSMonScript autrescript;
// Use this for initialization
void Start () {
transform.position = new Vector3 (-1000, -1000, -1000);
autrescript = autreobjet.GetComponent<FPSMonScript>();
}
// Update is called once per frame
void Update () {
if ((autrescript.aaspire == true)&&(autrescript.porteasp == true)) transform.position = new Vector3 (0, 0, 0);
else transform.position = new Vector3 (-1000, -1000, -1000);
}
}
Can you please post the actual error from the console with line numbers please. Anything that is a reference type can be null, saying you're getting a null reference is a needle in a small stack of words.
Your answer

Follow this Question
Related Questions
Highlighting background triggered from a 3d model 0 Answers
How to paint on a 3D model and create a texture? 3 Answers
Script won't execute on assigned 3d object but on simple cube 0 Answers
How do you add an animation to an imported 3D model? 1 Answer
Object doesn't export correctly from Blender to Unity 2 Answers