-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScoreAdder.cs
More file actions
22 lines (19 loc) · 766 Bytes
/
ScoreAdder.cs
File metadata and controls
22 lines (19 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
using UnityEngine;
/**
* This component increases a given "score" field whenever it is triggered.
*/
public class ScoreAdder : MonoBehaviour {
[Tooltip("Every object tagged with this tag will trigger adding score to the score field.")]
[SerializeField] string triggeringTag;
[SerializeField] NumberField scoreField;
// [SerializeField] int pointsToAdd;
private void OnTriggerEnter2D(Collider2D other) {
var pointsToAdd = other.GetComponent<EnemyDestroyOnTrigger2D>();
if (other.tag == triggeringTag && scoreField!=null && pointsToAdd) {
scoreField.AddNumber(pointsToAdd.GetEnemyScore());
}
}
public void SetScoreField(NumberField newTextField) {
this.scoreField = newTextField;
}
}