-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollectible2D.cs
More file actions
37 lines (22 loc) · 779 Bytes
/
Collectible2D.cs
File metadata and controls
37 lines (22 loc) · 779 Bytes
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Collectible2D : MonoBehaviour
{
public float rotationSpeed = 0.5f;
public GameObject onCollectEffect;
// Update is called once per frame
void Update()
{
transform.Rotate(0, 0, rotationSpeed);
}
private void OnTriggerEnter2D(Collider2D other) {
// Check if the other object has a PlayerController2D component
if (other.GetComponent<PlayerController2D>() != null) {
// Destroy the collectible
Destroy(gameObject);
// Instantiate the particle effect
Instantiate(onCollectEffect, transform.position, transform.rotation);
}
}
}