-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWater.cs
More file actions
68 lines (56 loc) · 2.36 KB
/
Water.cs
File metadata and controls
68 lines (56 loc) · 2.36 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
61
62
63
64
65
66
67
68
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Water : MonoBehaviour
{
public ParticleSystem bubbleEffect;
private ParticleSystem activeEffect;
public string splashInWater;
public Transform playerFeet;
private void OnTriggerEnter(Collider other)
{
Transform parent = other.transform.parent;
if (parent.CompareTag("Player") && other.GetComponentInParent<PlayerMovement>() != null && !other.CompareTag("PlayerHead"))
{
PlayerMovement movement = other.GetComponentInParent<PlayerMovement>();
movement.isSwimming = true;
FindObjectOfType<AudioManager>().Play(splashInWater);
SpawnBubbleEffect(other.transform.position, parent);
}
else if (other.CompareTag("PlayerHead"))
{
OxygenController oxygenScript = other.GetComponentInParent<OxygenController>();
oxygenScript.isHeadAboveWater = false;
FindObjectOfType<AudioManager>().FadeTrack("ShallowWaterMusic", 1f);
RenderSettings.fog = true;
}
}
private void OnTriggerExit(Collider other)
{
Transform parent = other.transform.parent;
// If Body leaves the water then we are NO longer swimming
if (parent.CompareTag("Player") && other.GetComponentInParent<PlayerMovement>() != null && !other.CompareTag("PlayerHead"))
{
PlayerMovement movement = other.GetComponentInParent<PlayerMovement>();
movement.isSwimming = false;
SpawnBubbleEffect(playerFeet.transform.position, parent);
FindObjectOfType<AudioManager>().Play(splashInWater, 0.96f);
}
// If head leaves the water only then we can breathe
else if (other.CompareTag("PlayerHead"))
{
OxygenController oxygenScript = other.GetComponentInParent<OxygenController>();
oxygenScript.isHeadAboveWater = true;
FindObjectOfType<AudioManager>().FadeTrack("SurfaceMusic", 1f);
RenderSettings.fog = false;
}
}
private void SpawnBubbleEffect(Vector3 position, Transform parent)
{
if (bubbleEffect != null)
{
activeEffect = Instantiate(bubbleEffect, position, Quaternion.identity, parent);
activeEffect.Play();
}
}
}