-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTarget.cs
More file actions
29 lines (23 loc) · 741 Bytes
/
Target.cs
File metadata and controls
29 lines (23 loc) · 741 Bytes
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
using System;
using UnityEngine;
using UnityEngine.Events;
public class Target : MonoBehaviour
{
[Serializable] public class HitEvent : UnityEvent<int> { }
public HitEvent OnHit = new HitEvent();
private void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.CompareTag("Projectile"))
FigureOutScore(collision.transform.position);
}
private void FigureOutScore(Vector3 hitPosition)
{
float distanceFromCenter = Vector3.Distance(transform.position, hitPosition);
int score = 0;
if (distanceFromCenter < 0.25f)
score = 15;
else if (distanceFromCenter < 0.5f)
score = 5;
OnHit.Invoke(score);
}
}