Hey guys , I need you to help me with my pick up script.
using UnityEngine; using System.Collections.Generic;
public class Keyring : MonoBehaviour { public AudioClip getKeySound; public float keyPickUpDistance = 5f;
private List _keys = new List();
public void AddKey(Key key)
{
_keys.Add(key);
if (getKeySound != null)
{
audio.PlayOneShot(getKeySound);
}
}
public bool HasKey(Key key)
{
return _keys.Contains(key);
}
void Update()
{
if (Input.GetKeyDown(KeyCode.E))
{
RaycastHit hit;
if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit, keyPickUpDistance))
{
Key key = hit.transform.GetComponent();
if (key != null)
{
AddKey(key);
key.transform.parent = transform;
key.transform.localPosition = Vector3.zero;
key.gameObject.SetActiveRecursively(false);
}
}
}
}
}
This script is attached to my player.When I press the E button my player take the key and it work correct but I need to make a GUI appear(when I press E) and ask me if I want to pick it up or no.Can someone help me with that , because I dont actually know how does the gui on C works.
Thank you for your time.