Add out-of-camp mechanic
This commit is contained in:
parent
5fdafd420d
commit
fbee51b6d4
@ -110,7 +110,11 @@ MonoBehaviour:
|
||||
RandomVarianceDuration: 0.2
|
||||
RandomVarianceMagnitude: 0.25
|
||||
LogBurningCooldown: 1
|
||||
CampRadius: 10
|
||||
OutOfCampFuelThreshold: 15
|
||||
OutOfCampFuelRateMultiplier: 0.2
|
||||
Fuel: 60
|
||||
OutOfCamp: 0
|
||||
--- !u!54 &7293540718676611162
|
||||
Rigidbody:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -15,8 +15,15 @@ public class Campfire : MonoBehaviour {
|
||||
[Tooltip("How long of a break the campfire takes between eating logs, if multiple are placed on it.")]
|
||||
public float LogBurningCooldown;
|
||||
|
||||
[Header("Out-of-camp mechanic")]
|
||||
public float CampRadius;
|
||||
[Tooltip("Fuel won't go below this threshold if the player is outside of the camp.")]
|
||||
public float OutOfCampFuelThreshold;
|
||||
public float OutOfCampFuelRateMultiplier;
|
||||
|
||||
[Header("Runtime values")]
|
||||
public float Fuel;
|
||||
public bool OutOfCamp = false;
|
||||
public float TimeToEnd {
|
||||
get {
|
||||
return Fuel - 0.7f;
|
||||
@ -33,12 +40,17 @@ public class Campfire : MonoBehaviour {
|
||||
private List<Item> LogQueue = new List<Item>();
|
||||
private float NextLogTime = 0;
|
||||
|
||||
private Transform Player;
|
||||
|
||||
private void Awake() {
|
||||
EnoughFuelColor = DynamicLight.color;
|
||||
FullRange = DynamicLight.range;
|
||||
Player = GameObject.FindGameObjectWithTag("Player").transform;
|
||||
}
|
||||
|
||||
private void Update() {
|
||||
TickFuel();
|
||||
|
||||
if (LogQueue.Count > 0 && Time.time > NextLogTime) {
|
||||
if (BurnLog(LogQueue[0])) {
|
||||
LogQueue.RemoveAt(0);
|
||||
@ -54,7 +66,6 @@ public class Campfire : MonoBehaviour {
|
||||
}
|
||||
RandomVariance = Mathf.Lerp(RandomVariance, NextRandomVariance, (Time.time - LastRandomVarianceChange) / RandomVarianceDuration);
|
||||
|
||||
Fuel = Mathf.Max(0, Fuel - Time.deltaTime);
|
||||
DynamicLight.range = Fuel / GoodFuelAmount / 2f * FullRange + RandomVariance;
|
||||
DynamicLight.color = Color.Lerp(DynamicLight.color, Fuel < GoodFuelAmount ? TooLowFuelColor : EnoughFuelColor, 10f * Time.deltaTime);
|
||||
Flame.Aliveness = Mathf.Log(Mathf.Max(0.01f, TimeToEnd), 10) / 2f;
|
||||
@ -64,6 +75,19 @@ public class Campfire : MonoBehaviour {
|
||||
}
|
||||
}
|
||||
|
||||
private void TickFuel() {
|
||||
OutOfCamp = true;
|
||||
if ((Player.position - transform.position).magnitude < CampRadius) {
|
||||
// Player is inside of the camp, tick fuel at normal rate
|
||||
Fuel -= Time.deltaTime;
|
||||
OutOfCamp = false;
|
||||
} else if (Fuel > OutOfCampFuelThreshold) {
|
||||
// Player is outside of the camp, and the campfire is within safe levels, tick fuel at a slow rate
|
||||
Fuel -= Time.deltaTime * OutOfCampFuelRateMultiplier;
|
||||
}
|
||||
Fuel = Mathf.Max(0, Fuel);
|
||||
}
|
||||
|
||||
private bool BurnLog(Item burnable) {
|
||||
if (Fuel >= GoodFuelAmount * 2) {
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user