134 lines
4.8 KiB
C#
134 lines
4.8 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Assets.Scripts
|
|
{
|
|
public class PlayerCamera : MonoBehaviour
|
|
{
|
|
UIHandler uihandler;
|
|
GameObject player;
|
|
Vector2 rotation = Vector2.zero;
|
|
public float speed = 1; //the sensibility
|
|
public float xMaxLimit = 25.0f;
|
|
public float xMinLimit = -25.0f;
|
|
GameObject interact;
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
uihandler = GameObject.Find("UIHandler").GetComponent<UIHandler>();
|
|
player = gameObject.transform.parent.gameObject;
|
|
interact = GameObject.Find("pnlInteract");
|
|
interact.transform.localScale = new Vector3(0,0,0);
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if(uihandler.canPlayerRotate()){
|
|
rotation.y += Input.GetAxis("Mouse X");
|
|
rotation.x += -Input.GetAxis("Mouse Y");
|
|
rotation.x = Mathf.Clamp(rotation.x, xMinLimit, xMaxLimit);
|
|
transform.eulerAngles = (Vector2)rotation * speed;
|
|
}
|
|
transform.position = new Vector3(transform.parent.transform.position.x, transform.position.y, transform.parent.transform.position.z);
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
showInformation();
|
|
}
|
|
|
|
public GameObject interactWithObject()
|
|
{
|
|
RaycastHit hit;
|
|
if (Physics.Raycast(transform.position, transform.forward, out hit, 3))
|
|
{
|
|
if (hit.collider.gameObject.tag.ToLower().Contains("object"))
|
|
{
|
|
return hit.collider.gameObject;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
void showInformation()
|
|
{
|
|
RaycastHit hit;
|
|
interact.transform.localScale = new Vector3(0,0,0);
|
|
if (Physics.Raycast(transform.position, transform.forward, out hit, Mathf.Infinity))
|
|
{
|
|
if (hit.collider.gameObject.tag.ToLower().Contains("object"))
|
|
{
|
|
string obj = hit.collider.gameObject.tag.Split(':')[1];
|
|
if(hit.distance <= 3 && !obj.ToLower().Equals("house")){
|
|
interact.transform.localScale = new Vector3(1,1,1);
|
|
}
|
|
switch (obj.ToLower())
|
|
{
|
|
case "tree":
|
|
displayInformation("Tree");
|
|
break;
|
|
case "stone":
|
|
displayInformation("Rock");
|
|
break;
|
|
case "npc":
|
|
displayInformation("NPC");
|
|
break;
|
|
case "enemy":
|
|
displayInformation(hit.collider.gameObject.GetComponent<Enemy>().getEnemyName());
|
|
break;
|
|
case "house":
|
|
displayInformation("House");
|
|
break;
|
|
case "door":
|
|
displayInformation("Door");
|
|
break;
|
|
case "chest":
|
|
displayInformation("Chest");
|
|
break;
|
|
case "ore":
|
|
if(hit.collider.gameObject.name.ToLower().Contains("iron")){
|
|
displayInformation("Iron ore");
|
|
}
|
|
else if(hit.collider.gameObject.name.ToLower().Contains("gold")){
|
|
displayInformation("Gold ore");
|
|
}
|
|
else if(hit.collider.gameObject.name.ToLower().Contains("copper")){
|
|
displayInformation("Copper ore");
|
|
}
|
|
else if(hit.collider.gameObject.name.ToLower().Contains("tin")){
|
|
displayInformation("Tin ore");
|
|
}
|
|
break;
|
|
default:
|
|
uihandler.hideInformation();
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
uihandler.hideInformation();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
uihandler.hideInformation();
|
|
}
|
|
}
|
|
|
|
private void displayInformation(string information)
|
|
{
|
|
if (!uihandler.isPlayerInFight())
|
|
{
|
|
uihandler.displayInformation(information);
|
|
}
|
|
else
|
|
{
|
|
uihandler.hideInformation();
|
|
}
|
|
}
|
|
}
|
|
} |