reworked interactions, fixed health depleting from testing
This commit is contained in:
54
Assets/Scripts/InteractableObjects/Door.cs
Normal file
54
Assets/Scripts/InteractableObjects/Door.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Assets.Scripts.InteractableObjects
|
||||
{
|
||||
public class Door : InteractableObject
|
||||
{
|
||||
public bool hasInteracted = false;
|
||||
bool isOpen = false;
|
||||
|
||||
public override void handleInteraction(GameObject player)
|
||||
{
|
||||
if (hasInteracted)
|
||||
{
|
||||
GameObject.Find("UIHandler").GetComponent<UIHandler>().showMessage("ERROR;"+TextHandler.getText("triedHouse"));
|
||||
}
|
||||
else
|
||||
{
|
||||
int openChance = new System.Random().Next(4);
|
||||
if(openChance == 0){
|
||||
gameObject.GetComponent<Animator>().Play("DoorOpen");
|
||||
Destroy(gameObject.GetComponent<BoxCollider>());
|
||||
isOpen = true;
|
||||
}
|
||||
else{
|
||||
GameObject.Find("UIHandler").GetComponent<UIHandler>().showMessage("ERROR;"+TextHandler.getText("lockedHouse"));
|
||||
}
|
||||
}
|
||||
hasInteracted = true;
|
||||
}
|
||||
|
||||
public string saveHouse(){
|
||||
string result = "";
|
||||
result = result + FileHandler.generateJSON("objectname", "\"" + transform.parent.name + "\",\r\n");
|
||||
result = result + FileHandler.generateJSON("hasInteracted", "\"" + hasInteracted + "\",\r\n");
|
||||
result = result + FileHandler.generateJSON("isOpen", "\"" + isOpen + "\",\r\n");
|
||||
result = result + FileHandler.generateJSON("gotItem", "\"" + transform.parent.Find("chest").Find("Body").GetComponent<Chest>().saveChest() + "\"");
|
||||
return result;
|
||||
}
|
||||
|
||||
public void loadHouse(JToken json){
|
||||
hasInteracted = bool.Parse(json["hasInteracted"].ToString());
|
||||
isOpen = bool.Parse(json["isOpen"].ToString());
|
||||
transform.parent.Find("chest").Find("Body").GetComponent<Chest>().loadChest(bool.Parse(json["gotItem"].ToString()));
|
||||
if(isOpen){
|
||||
gameObject.GetComponent<Animator>().Play("DoorOpen");
|
||||
Destroy(gameObject.GetComponent<BoxCollider>());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user