Files
brickcraft/Assets/Scripts/Player/TriggerDetector.cs
tetreum e91da0be3d + Players can now swim on water blocks
+ Blocks can have specific layers
- Ignore log files
2020-12-30 12:53:18 +01:00

33 lines
1.1 KiB
C#

using Brickcraft;
using System.Collections.Generic;
using UnityEngine;
public class TriggerDetector : MonoBehaviour
{
public List<string> waterBlocks = new List<string>();
private void OnTriggerEnter(Collider other) {
if (other.tag == "Block" && Server.bricks.ContainsKey(other.name)) {
if (Server.bricks[other.name].item.layer == (int)Game.Layers.Water) {
if (waterBlocks.Count < 1) {
Player.Instance.isOnWater = true;
SoundManager.Instance.play(SoundManager.EFFECT_ENTER_WATER);
}
waterBlocks.Add(other.name);
}
}
}
private void OnTriggerExit(Collider other) {
if (other.tag == "Block" && Server.bricks.ContainsKey(other.name)) {
if (Server.bricks[other.name].item.layer == (int)Game.Layers.Water) {
waterBlocks.Remove(other.name);
if (waterBlocks.Count < 1) {
Player.Instance.isOnWater = false;
Player.Instance.firstPersonController.resetGravity();
}
}
}
}
}