-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLightning.cs
More file actions
60 lines (51 loc) · 1.73 KB
/
Lightning.cs
File metadata and controls
60 lines (51 loc) · 1.73 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;
using System.Collections;
using System.Collections.Generic;
using FishNet.Object;
using UnityEngine;
using Random = UnityEngine.Random;
public class Lightning : NetworkBehaviour
{
private LayerMask i_PropLayerMask;
[SerializeField] private AudioSource i_Audio;
[SerializeField] private GameObject i_LightningVisuals;
[SerializeField] private AudioClip i_LightningSound;
private void Awake()
{
i_PropLayerMask = LayerMask.GetMask("Prop", "PlayerProp");
}
public override void OnStartServer()
{
base.OnStartServer();
StartCoroutine(ServerLightningDelay());
}
private IEnumerator ServerLightningDelay()
{
yield return new WaitForSeconds(1f);
Collider[] l_Colliders = new Collider[5];
int l_Collisions = 0;
l_Collisions = Physics.OverlapSphereNonAlloc(transform.position, 0.15f, l_Colliders, i_PropLayerMask);
for (int i = 0; i < l_Collisions; i++)
{
if (l_Colliders[i].GetComponentInParent<ServerSideHealth>())
{
l_Colliders[i].GetComponentInParent<ServerSideHealth>().Damage(1);
}
}
}
public override void OnStartClient()
{
base.OnStartClient();
StartCoroutine(LightningDelay());
}
private IEnumerator LightningDelay()
{
// INFO: warning sound plays on awake
yield return new WaitForSeconds(1f);
i_Audio.pitch += Random.Range(-0.05f, 0.05f);
i_Audio.PlayOneShot(i_LightningSound);
i_LightningVisuals.SetActive(true);
yield return new WaitForSeconds(0.5f);
i_LightningVisuals.SetActive(false);
}
}