-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPowerUpScript.cs
More file actions
56 lines (47 loc) · 1.48 KB
/
PowerUpScript.cs
File metadata and controls
56 lines (47 loc) · 1.48 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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PowerUpScript : MonoBehaviour
{
private float speed = 2.5f;
[SerializeField] private int powerUpId;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.Translate(Vector3.down * speed * Time.deltaTime);
if (transform.position.y < -6.0f)
{
Destroy(this.gameObject);
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("Player"))
{
//script communcation - IMPORTANT!!
PlayerScript P = collision.GetComponent<PlayerScript>();
// look at what we collided with
// look at components in the inspector
// find the one called Player (the script)
// link to it
if (P != null)
{
if (powerUpId == 1)
P.RifleShotOn();
else if (powerUpId == 2)
P.GreenShotOn();
else if (powerUpId == 3)
P.SpeedBoostPowerUpOn();
else if (powerUpId == 4)
P.SpeedDownPowerUpOn();
else if (powerUpId == 5)
P.LifePowerUp();
}
Destroy(this.gameObject);
}
}
}