Question by
meksikietis222 · Jul 23, 2019 at 02:48 PM ·
errorgameobject3dscript.
NullReferenceException: Object reference not set to an instance of an object error?
Anyone know why im getting this error? What im trying to do is if in my hotbar item name is "AKM" then enable weapon gameobject.
What i know so far is that script can't find weapon gameobject.
Weapon gameobject https://imgur.com/a/m5EaY0q
Full error: NullReferenceException: Object reference not set to an instance of an object WpnBack.Update () (at Assets/Resources/Weapons/WpScripts/WpnBack.cs:20)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WpnBack : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if(GetComponent<ItemOnObject>().item.itemName == "AKM")
{
GameObject.FindWithTag("AKM").SetActive(true);
Debug.Log("Yes");
}
if(GetComponent<ItemOnObject>().item.itemName != "AKM")
{
GameObject.FindWithTag("AKM").SetActive(false);
Debug.Log("No");
}
}
}
Comment