-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnlargePowerup.cs
52 lines (44 loc) · 1.68 KB
/
EnlargePowerup.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
41
42
43
44
45
46
47
48
49
50
51
52
using UnityEngine;
public class EnlargePowerup : MonoBehaviour
{
GameObject circle;
float startTime;
public float increaseRate;
public float stayTime;
public float increaseSpeed;
float targetSize;
float originalSize;
private void Start()
{
startTime = 0;
PlayerPrefs.SetInt("EnlargePowerupExists", 1);
}
public void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.CompareTag("Player"))
{
if (PlayerPrefs.GetInt("SoundEnabled", 1) == 1)
FindObjectOfType<AudioManager>().PlayWithPitch("ButtonSound" , 2f);
circle = GameObject.FindGameObjectWithTag("Circle");
originalSize = circle.transform.localScale.x;
targetSize = originalSize * (increaseRate + 1 - (PlayerPrefs.GetInt("circleSize", 10) / 400f) );
startTime = Time.time;
gameObject.GetComponent<SpriteRenderer>().enabled = false;
gameObject.GetComponent<CircleCollider2D>().enabled = false;
}
}
private void Update()
{
if( originalSize < targetSize)
{
circle.transform.localScale = circle.transform.localScale + new Vector3(Time.deltaTime * increaseSpeed, Time.deltaTime * increaseSpeed, 0);
originalSize = circle.transform.localScale.x;
}
if( startTime > 0 && Time.time - startTime > stayTime)
{
circle.transform.localScale = circle.transform.localScale / (increaseRate + 1 - (PlayerPrefs.GetInt("circleSize", 10) / 400f)); ;
PlayerPrefs.SetInt("EnlargePowerupExists", 0);
Destroy(this.gameObject);
}
}
}