I have this class:
using UnityEngine;
using System.Collections;
public class Monster1 : MonoBehaviour {
private GameObject monster_;
// Use this for initialization
public Monster1(){
monster_ = (GameObject)Instantiate(Resources.Load("Monster1"));
float height = Random.Range(0, Screen.height);
Vector2 monster1position = new Vector2(Screen.width, height);
monster1position = camera.ScreenToWorldPoint(monster1position);
monster_.transform.position = monster1position;
}
void Start () {
}
// Update is called once per frame
void Update () {
}
When I am trying to instantiate an object of that class there is a NullReferenceException
.
void Start () {
Monster1 monster1 = new Monster1();
}
Any idea why this is happening and how can I fix it?