Hey, Currently I’m building a FPS Type Game. When the player Collides with a pick up object (Such As AK47) A pop up message appears saying “press E to Equip.” I thought if I add a Boolean value for when the player collides with an object that when the bool = true and E is pressed the “Wild” AK would be hidden and the Inventory AK would appear however they just stay the same.
Any help would be highly appreciated as I’m only fairly new to unity.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PickUpFinder : MonoBehaviour
{
public GameObject MessagePanel;
private bool AKavailable = false;
public GameObject AK;
public GameObject invAK;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.E) && !AKavailable)
{
Debug.Log("E");
AK.SetActive(false);
invAK.SetActive(true);
}
}
private void OnCollisionEnter(Collision collisionInfo)
{
if (collisionInfo.collider.tag == "PickUp")
{
MessagePanel.SetActive(true);
AKavailable = true;
}
}
private void OnCollisionExit(Collision collisionInfo)
{
if (collisionInfo.collider.tag != null)
MessagePanel.SetActive(false);
AKavailable = false;
}
}