80 lines
2.4 KiB
C#
80 lines
2.4 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
|
|
{
|
|
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);
|
|
}
|
|
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:
|
|
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);
|
|
}
|
|
}
|
|
}
|