-
Notifications
You must be signed in to change notification settings - Fork 0
/
Star.cs
40 lines (31 loc) · 876 Bytes
/
Star.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
40
using UnityEngine;
public class Star : MonoBehaviour
{
float fallSpeed;
Rigidbody2D rb;
SpriteRenderer spriteRenderer;
Transform player;
public GameObject dieEffect;
private void Awake()
{
rb = GetComponent<Rigidbody2D>();
spriteRenderer = GetComponent<SpriteRenderer>();
player = FindObjectOfType<Player>().transform;
}
private void Start()
{
fallSpeed = Random.Range(7.5f, 10f);
transform.localScale *= Random.Range(0.5f, 2f);
spriteRenderer.color = Random.ColorHSV();
}
private void Update()
{
transform.eulerAngles += new Vector3(0f, 0f, 10f * Time.deltaTime);
if (transform.position.y < player.position.y - 10f)
Destroy(gameObject);
}
private void FixedUpdate()
{
rb.velocity = new Vector2(0f, -fallSpeed);
}
}