-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBreakSocialDistance.cs
More file actions
60 lines (43 loc) · 1.63 KB
/
BreakSocialDistance.cs
File metadata and controls
60 lines (43 loc) · 1.63 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
57
58
59
60
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
//This script handles calculating if the player/ gameobject has broken social distancing rules, and
//what happens when they do. This script also holds the player/ gameobjects overall risk of infection.
public class BreakSocialDistance : MonoBehaviour
{
public static double playerRisk;
public CalculateInfected infectioncount;
public static int transmissionRisk;
private bool wearingMasks;
public Transform player;
public Transform other;
private void Start()
{
//A rough estimate of transmission according to our model is 5% when in contact with an infected individual. If everyone
//in the space is wearing a mask, this decreases the risk by roughly 60%. A rough estimate of risk can be:
if (wearingMasks)
transmissionRisk = 2;
else
transmissionRisk = 5;
}
//One method is to use a collision event to determine when the player has broken social distancing measures.
void OnCollisionEnter(Collision col)
{
if (col.gameObject.tag == "player") {
IncreaseRisk(transmissionRisk);
}
}
//Another method is to simply see if the distance between two gameobjects is less than 6ft (what this could mean in your game
//may vary drastically.
private void Update()
{
float dist = Vector2.Distance(other.position, player.position);
if (dist <= 6)
IncreaseRisk(transmissionRisk);
}
void IncreaseRisk(int risk)
{
playerRisk += risk;
}
}