THE EROR I GET
NullReferenceException: Object reference not set to an instance of an object
ItemSpawner.Update () (at Assets/Scripts/ItemSpawner.cs:41)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class ItemSpawner : MonoBehaviour
{
[SerializeField] private GameObject Itemspawn;
[SerializeField] private int NumItems = 12;
[SerializeField] private float Xbond = 12f;
[SerializeField] private float Zbond = 12f;
[SerializeField] private float Ybond = 2f;
[SerializeField] private float TimeTOSpawn = 1.2f;
[SerializeField] private float currentTime;
SpawnControlls spawncontrolls;
void SpreadItems()
{
Vector3 randomPos = new Vector3(Random.Range(-Xbond, Xbond), Random.Range(-Zbond, Zbond), Random.Range(-Ybond, Ybond));
GameObject clone = Instantiate(Itemspawn, transform.position + randomPos, Quaternion.identity);
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
currentTime += Time.deltaTime;
bool isKeyHeld = spawncontrolls.Player.PPspawn.ReadValue<float>() > 0.1f;
if (isKeyHeld)
{
Debug.Log("WORKING");
if (currentTime > TimeTOSpawn)
{
SpreadItems();
currentTime = 0;
}
}
}
}
im trying to instantiate on the bonds i created i tried for hours to chnge the code but i always get the same erorr.