2021-01-17 17:56:17 +01:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2021-01-22 17:34:44 +01:00
|
|
|
|
//Define the behavior of a soft obstacle (Slow movement and chance of falling)
|
2021-01-17 17:56:17 +01:00
|
|
|
|
//TODO : Effect on clients ? (Lower Tips/Repu ?)
|
|
|
|
|
[RequireComponent(typeof(Collider2D))]
|
|
|
|
|
public class SoftObstacle : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
[SerializeField]
|
|
|
|
|
float effectChance = 100.0f; //Probabily of fall on entering.
|
|
|
|
|
[SerializeField]
|
|
|
|
|
float mvtSlow = 1.0f; //Scale of movement slowdown (1.0f = no change).
|
|
|
|
|
|
|
|
|
|
[SerializeField]
|
2021-01-22 17:34:44 +01:00
|
|
|
|
float lifeTime = -1.0f; //Time before self-destruct (Negative value to prevent self-destruct)
|
2021-01-17 17:56:17 +01:00
|
|
|
|
float lifeTimer;
|
|
|
|
|
|
|
|
|
|
Tavernkeeper_controller player;
|
|
|
|
|
|
|
|
|
|
// Start is called before the first frame update
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
|
|
|
|
lifeTimer=lifeTime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
2021-01-22 17:34:44 +01:00
|
|
|
|
if(lifeTimer>0)
|
2021-01-17 17:56:17 +01:00
|
|
|
|
{
|
2021-01-22 17:34:44 +01:00
|
|
|
|
lifeTimer -= Time.deltaTime;
|
|
|
|
|
if(lifeTimer<0)
|
|
|
|
|
{
|
|
|
|
|
Destroy(gameObject);
|
|
|
|
|
}
|
2021-01-17 17:56:17 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//TODO : Trigger falling animation on tavernkeeper
|
|
|
|
|
void OnTriggerEnter2D(Collider2D other)
|
|
|
|
|
{
|
|
|
|
|
if(other.tag=="Player")
|
|
|
|
|
{
|
|
|
|
|
player=other.GetComponent<Tavernkeeper_controller>();
|
|
|
|
|
player.mvt_speed=player.mvt_speed/mvtSlow; //Slow movement speed
|
|
|
|
|
|
|
|
|
|
if(Random.Range(0.0f, 99.9f)<effectChance)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("Woops");
|
|
|
|
|
player.emptyHands();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OnTriggerExit2D(Collider2D other)
|
|
|
|
|
{
|
|
|
|
|
if(other.tag=="Player")
|
|
|
|
|
{
|
|
|
|
|
player.mvt_speed=player.mvt_speed*mvtSlow; //Restore movement speed
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OnDestroy()
|
|
|
|
|
{
|
|
|
|
|
EventManager.Instance.destroyEvent(gameObject);
|
|
|
|
|
}
|
|
|
|
|
}
|