-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSleepInteractable.cs
More file actions
66 lines (58 loc) · 1.71 KB
/
SleepInteractable.cs
File metadata and controls
66 lines (58 loc) · 1.71 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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SleepInteractable : Interactable
{
[SerializeField]
private int cost = 50;
[SerializeField]
private ExclusionList enemyExclusions;
private bool isSleeping = false;
private void LateUpdate()
{
if (isSleeping)
{
if (Input.GetKeyDown(KeyCode.Space))
{
isSleeping = false;
SceneTransitionAnimation.PlayFadeIn();
player.GetComponent<MyCharacterController>().EnableMovement();
}
}
}
public override void Interact()
{
base.Interact();
CheckGold();
}
private void CheckGold()
{
var playerGold = Inventory.instance.inventorySO.gold;
if (playerGold > cost)
{
Inventory.instance.inventorySO.gold -= cost;
Inventory.instance.onItemChangedCallback?.Invoke();
Sleep();
RestoreEnemies();
}
else
{
MessagePanelSystem.ShowMessage($"Not enough gold. Renting this bed costs {cost} gold.");
}
}
private void RestoreEnemies()
{
enemyExclusions.Clear();
}
private void Sleep()
{
MessagePanelSystem.ShowMessage("Sleeping...");
SceneTransitionAnimation.PlayFadeOut();
player.GetComponent<MyCharacterController>().DisableMovement();
isSleeping = true;
player.GetComponent<Character>().GainHealth(9999);
player.GetComponent<Character>().GainMana(9999);
player.GetComponent<Character>().GainStamina(9999);
}
}