- Home /
Pick Up like in Silent Hill
Hey everyone , I'm making a game and I want to change my pick up system a little bit. there is my 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);
}
}
}
}
}
(Attached to my Player)
I'm trying to create a function , when I press the USE key(E) I want it to ask me if I actually want to pick up this items or no like in silent hill 1. Can anyone help me with that ? Thank you for your time =)
Answer by dorpeleg · Mar 23, 2013 at 03:10 PM
You need to create an OnGUI() function that will pop a window up upon pressing E.
In the window, have two buttons saying: yes, no.
If user clicks no, close the window and do nothing.
If user clicks yes, run your pickup code.
Your answer
Follow this Question
Related Questions
inventory system some help and guides please :) 1 Answer
Adding 1 point after collison 1 Answer
Pick up objects 2 Answers
How To Make A Numeric Inventory System? 0 Answers
Resource Script 2 Answers