-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLaserShooter.cs
More file actions
44 lines (38 loc) · 1.38 KB
/
LaserShooter.cs
File metadata and controls
44 lines (38 loc) · 1.38 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
using UnityEngine;
/**
* This component spawns the given laser-prefab whenever the player clicks a given key.
* It also updates the "scoreText" field of the new laser.
*/
public class LaserShooter: ClickSpawner {
[SerializeField] NumberField scoreField;
Vector3 OriginalVelocity;
bool ability = false;
private void Start() {
OriginalVelocity = new Vector3(base.velocityOfSpawnedObject.x, base.velocityOfSpawnedObject.y, base.velocityOfSpawnedObject.z);
}
public void SetAbility(bool state) {
ability = state;
}
protected override GameObject spawnObject() {
GameObject newObject = base.spawnObject(); // base = super
// Modify the text field of the new object.
ScoreAdder newObjectScoreAdder = newObject.GetComponent<ScoreAdder>();
if (newObjectScoreAdder)
newObjectScoreAdder.SetScoreField(scoreField);
return newObject;
}
private void Update() {
if (spawnAction.WasPressedThisFrame()) {
if(gameObject.tag == "Player1" && ability) {
base.velocityOfSpawnedObject.x = -7;
spawnObject();
base.velocityOfSpawnedObject.x = 7;
spawnObject();
base.velocityOfSpawnedObject.x = 0;
spawnObject();
} else {
spawnObject();
}
}
}
}