pick up object using a key and then playing a sound
For starters, I've been trying to make this horror game and so far everything is going well, the only issue is that I'm sort of new to programming and have been looking up on internet how to make this code. I can't seem to find a tutorial that explains clearly how to do this step by step. For the script I would like it when the player comes in close proximity to a game object (the box collider around the object) and presses a key, for example, pressing the 'E' key on the keyboard, and then once the player presses the E key, the object will play a sound only one time and the object that is picked up will disappear the moment the key is pressed. Here is my script so far I have it able to play the sound effect, this script is attached the pickup object in my scene.
public class CassetteTapeOne : MonoBehaviour {
void OnTriggerEnter(Collider other)
{
AudioSource source = GetComponent<AudioSource>();
if (other.gameObject.tag == "Player")
{
KeyCode key = KeyCode.E;
if (Input.GetKeyDown( key )){
source.Play();
}
}
}
}
I'm simply asking for help on here, if you know how to write this script please let me know, I would really appreciate the help.
Your answer
Follow this Question
Related Questions
Random Text Based Game 0 Answers
Script to random set active a child object? 0 Answers
Joystick Movement Not Smooth Enough 0 Answers
How do I acess a volume's Weight value from a script? 0 Answers