2023-04-14 20:25:54 +02:00

87 lines
2.8 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
namespace Assets.Scripts
{
public class House : MonoBehaviour
{
bool hasInteracted;
public GameObject houseObject;
public Vector3 playerPosition;
GameObject houseInstance;
bool gotItem;
// Start is called before the first frame update
void Start()
{
hasInteracted = false;
gotItem = false;
}
// Update is called once per frame
void Update()
{
}
public void interact()
{
if (hasInteracted)
{
GameObject.Find("UIHandler").GetComponent<UIHandler>().showMessage("ERROR;You already entered this house");
}
else
{
int openChance = new System.Random().Next(4);
if(openChance == 0){
playerPosition = GameObject.Find("Player").transform.position;
houseInstance = Instantiate(houseObject);
houseInstance.transform.position = new Vector3(playerPosition.x, 50, playerPosition.z);
houseInstance.transform.localScale = new Vector3(1, 1, 1);
GameObject.Find("Player").transform.position = new Vector3(playerPosition.x, 51, playerPosition.z);
}
else{
GameObject.Find("UIHandler").GetComponent<UIHandler>().showMessage("ERROR;This house is locked.");
}
}
hasInteracted = true;
}
public void getItem()
{
if (gotItem)
{
GameObject.Find("UIHandler").GetComponent<UIHandler>().showMessage("ERROR;You already looted this chest");
}
else
{
Item item;
int luck = GameObject.Find("Player").GetComponent<Player>().getStats()[11];
int type = new System.Random().Next(3);
switch (type)
{
case 0:
// Maybe add luck to increase chance for equipment
item = new Equipment(luck);
break;
case 1:
item = new Book(luck);
break;
default:
item = new Item(luck);
break;
}
GameObject.Find("Inventory").GetComponent<Inventory>().addItem(item);
}
gotItem = true;
}
public void leaveHouse()
{
GameObject.Find("Player").transform.position = playerPosition;
Destroy(houseInstance);
}
}
}