-
Notifications
You must be signed in to change notification settings - Fork 0
/
Asteroid.cs
35 lines (30 loc) · 1.05 KB
/
Asteroid.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Asteroid : MonoBehaviour
{
[SerializeField] private GameObject _explosionPrefab;
private SpawnManager _spawnManager;
[SerializeField] private float _minSpeed = 30f;
[SerializeField] private float _maxSpeed = 100f;
private float _rotateSpeed;
// Start is called before the first frame update
void Start()
{
_spawnManager = GameObject.Find("Spawn_Manager").GetComponent<SpawnManager>();
_rotateSpeed = Random.Range(_minSpeed, _maxSpeed);
}
// Update is called once per frame
void Update()
{
transform.Rotate(Vector3.forward * _rotateSpeed * Time.deltaTime);
}
private void OnTriggerEnter2D(Collider2D other) {
if (other.gameObject.CompareTag("Laser")) {
Instantiate(_explosionPrefab, transform.position, Quaternion.identity);
Destroy(other.gameObject);
Destroy(GetComponent<Collider2D>());
Destroy(this.gameObject, 0.25f);
}
}
}