-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollectible.cs
More file actions
39 lines (32 loc) · 1.01 KB
/
Collectible.cs
File metadata and controls
39 lines (32 loc) · 1.01 KB
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;
public class Collectible : MonoBehaviour
{
public float rotationSpeed;
public GameObject onCollectEffect;
public AudioClip collectSFX; // Tambahan: SFX ketika dikoleksi
public float sfxVolume; // Volume SFX
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.Rotate(0, rotationSpeed, 0);
}
private void OnTriggerEnter(Collider other) {
if (other.CompareTag("Player")) {
// Destroy the collectible
Destroy(gameObject);
// instantiate the particle effect
Instantiate(onCollectEffect, transform.position, transform.rotation);
// Mainkan sound effect
if(collectSFX != null)
{
AudioSource.PlayClipAtPoint(collectSFX, transform.position, sfxVolume);
}
}
}
}