-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKey.cs
39 lines (31 loc) · 1.02 KB
/
Key.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(AudioSource))]
public class Key : MonoBehaviour
{
private bool keyCollected = false;
private AudioSource audioSource = null;
public GameObject KeyPoof;
void Start()
{
this.audioSource = this.gameObject.GetComponent<AudioSource> ();
}
void Update()
{
this.gameObject.transform.rotation = this.gameObject.transform.rotation * Quaternion.Euler (new Vector3 (0.0f, 0.0f, 1.0f));
this.gameObject.transform.position = this.gameObject.transform.position + new Vector3 (0.0f, Mathf.Sin (Time.time) * Time.deltaTime * 0.25f, 0.0f);
}
public void OnKeyClicked()
{
keyCollected = true;
this.gameObject.GetComponent<Renderer> ().enabled = false; // Hide the key
Object.Instantiate(KeyPoof, this.gameObject.transform.position, this.gameObject.transform.rotation);
this.audioSource.Play ();
Destroy (this.gameObject, this.audioSource.clip.length);
}
public bool IsKeyCollected()
{
return this.keyCollected;
}
}