- Home /
Question by
Aleeeeeeeeee · Apr 16, 2015 at 07:18 PM ·
instantiatescript.instanceinstatiate
NullReferenceException: Object reference not set to an instance of an object ???
using UnityEngine; using System.Collections;
public class GameController : MonoBehaviour { public GameObject enemy; public GameObject laser;
float spawnTimer;
float shootTimer;
void Start () {
spawnTimer = 1.0f;
}
void Update () {
spawnTimer -= Time.deltaTime;
shootTimer -= Time.deltaTime;
if (spawnTimer <= 0.0f)
{
GameObject instance = (GameObject)Instantiate(enemy, new Vector3(10,Random.Range(-4.0f,4.0f),-2.0f), transform.rotation);
spawnTimer = 1.0f;
}
if (shootTimer <= 0.0f)
{
if (Input.GetButton("Fire1"))
{
Vector3 spawnLaserPos = Camera.main.ScreenToWorldPoint(new Vector3(-5.0f, Input.mousePosition.y,8));
Instantiate(laser, spawnLaserPos, Quaternion.identity);
shootTimer = 0.4f;
}
}
}
}
Comment