Repository navigation
Expand file tree
/
Copy pathJewelEffect.cs
More file actions
82 lines (69 loc) · 2.35 KB
/
Copy pathJewelEffect.cs
File metadata and controls
82 lines (69 loc) · 2.35 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class JewelEffect : Entity
{
/**<summary> 消えるまでの時間 </summary>*/
private readonly float LIFE = 0.9f;
/**<summary> 高さの最大値 </summary>*/
private readonly float MAX_HEIGHT = 1.3f;
private float bornTime;
private float originalY;
/**<summary> キラキラを生成する周期 </summary>*/
private readonly float TWINKLE_PERIOD = 0.1f;
private float lastTwinkleTime = 0;
// Start is called before the first frame update
protected override void Start()
{
base.Start();
Game game = Game.Get();
bornTime = game.time;
originalY = transform.position.y;
float rate = ((bornPositionHash >> 4) & 0xf) / 16f;
lastTwinkleTime = game.time - TWINKLE_PERIOD * rate;
}
// Update is called once per frame
protected override void Update()
{
base.Update();
Game game = Game.Get();
if (game.time - bornTime > LIFE)
{
Die();
}
float lifeRate = (game.time - bornTime) / LIFE; // [0, 1]
// 高さ
float height
= MAX_HEIGHT * 4 * lifeRate * (1 - lifeRate); // [0, MAX_HEIGHT]
Vector2 pos = transform.position;
pos.y = originalY + height;
transform.position = pos;
// 回転
Vector3 angle = transform.eulerAngles;
angle.y = (
(game.time - bornTime) * 3f +
(bornPositionHash & 0xf) / 16f
) * 360;
transform.eulerAngles = angle;
// Twinkle
if (game.time > lastTwinkleTime + TWINKLE_PERIOD)
{
lastTwinkleTime += TWINKLE_PERIOD;
Func<float, float> f = x => (1 - Mathf.Cos(Mathf.PI * x)) / 2f;
float xRate = f(UnityEngine.Random.value);
float yRate = f(UnityEngine.Random.value);
float x = transform.localScale.x * (-0.5f + xRate);
float y = transform.localScale.y * (-0.5f + yRate);
string name = "Twinkle";
GameObject prefab
= Resources.Load<GameObject>(@"Prefabs/" + name);
GameObject obj = Instantiate(
prefab,
transform.position + new Vector3(x, y, -1),
Quaternion.Euler(0, 0, 0)
);
obj.name = name;
}
}
}