0
This is my first game and it runs on Unity but just when I use the shoot button of this error "Unity - Error: Object Reference not set to an instance of an Object - Instantiate". follows the code down below:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Gun : MonoBehaviour {
private SpriteRenderer mySpriteRenderer;
public int damage = 40;
public GameObject bullet;
private Transform SpawnerB;
public float fireRate = 0.3f;
public float nextFire = 0.0f;
// Start is called before the first frame update
void Start () {
mySpriteRenderer = GetComponent<SpriteRenderer> ();
bullet = GameObject.FindWithTag ("bull");
}
// Update is called once per frame
void Update () {
Vector3 mousePos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
transform.rotation = Quaternion.LookRotation (Vector3.forward, mousePos - transform.position);
if (Input.GetButtonDown ("Fire1") && Time.time > nextFire) {
nextFire = Time.time + fireRate;
Instantiate (bullet, SpawnerB.position, transform.rotation, );
}
}
}