I am trying to follow a tutorial trying to get bullet holes to work but it says there is an NullReferenceException error on line 49. Here is my code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WeaponHandler : MonoBehaviour
{
public Gun[] loadout;
public Transform weaponParent;
public GameObject bulletholePrefab;
public LayerMask canBeShot;
private GameObject currentWeapon;
void Start()
{
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Alpha1)) Equip(0);
if (currentWeapon != null)
{
if(Input.GetMouseButtonDown(0))
{
Shoot();
}
}
}
void Equip(int p_id)
{
if (currentWeapon != null) Destroy(currentWeapon);
GameObject t_newWeapon = Instantiate(loadout[p_id].prefab, weaponParent.position, weaponParent.rotation, weaponParent) as GameObject;
t_newWeapon.transform.localPosition = Vector3.zero;
t_newWeapon.transform.localEulerAngles = Vector3.zero;
currentWeapon = t_newWeapon;
}
void Shoot()
{
Transform t_spawn = transform.Find("Cameras/JimmyCamera");
RaycastHit t_hit = new RaycastHit();
if(Physics.Raycast(t_spawn.position, t_spawn.forward, out t_hit, 1000f, canBeShot))
{
GameObject t_newHole = Instantiate(bulletholePrefab, t_hit.point + t_hit.normal * 0.001f, Quaternion.identity) as GameObject;
t_newHole.transform.LookAt(t_hit.point + t_hit.normal);
Destroy(t_newHole, 10f);
}
}
}
Can anyone please help me fix this error