162 lines
6.2 KiB
C#
162 lines
6.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using Assets.Scripts.InteractableObjects;
|
|
|
|
namespace Assets.Scripts.Player
|
|
{
|
|
public class PlayerCamera : MonoBehaviour
|
|
{
|
|
UIHandler uihandler;
|
|
GameObject interact;
|
|
public float mouseSpeed = 10f; //the sensibility
|
|
public float controllerSpeed = 1f; //the sensibility
|
|
float xMaxLimit = 45.0f;
|
|
float xMinLimit = -45.0f;
|
|
Vector2 rotation = Vector2.zero;
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
uihandler = GameObject.Find("UIHandler").GetComponent<UIHandler>();
|
|
interact = GameObject.Find("pnlInteract");
|
|
interact.transform.localScale = new Vector3(0, 0, 0);
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
public void lookAround(Vector2 view, bool isController)
|
|
{
|
|
GameObject target = GameObject.Find("targetLooking");
|
|
if (isController)
|
|
{
|
|
target.transform.localPosition = target.transform.localPosition + new Vector3(view.x,view.y,0) * controllerSpeed * Time.deltaTime;
|
|
}
|
|
else
|
|
{
|
|
target.transform.localPosition = target.transform.localPosition + new Vector3(view.x,view.y,0) * Mathf.Pow(mouseSpeed,2) * Time.deltaTime;
|
|
}
|
|
|
|
if(target.transform.localPosition.x >= 3){
|
|
target.transform.localPosition = new Vector3(3f,target.transform.localPosition.y,target.transform.localPosition.z);
|
|
}
|
|
if(target.transform.localPosition.x <= -3){
|
|
target.transform.localPosition = new Vector3(-3f,target.transform.localPosition.y,target.transform.localPosition.z);
|
|
}
|
|
if(target.transform.localPosition.y >= 2){
|
|
target.transform.localPosition = new Vector3(target.transform.localPosition.x,2f,target.transform.localPosition.z);
|
|
}
|
|
if(target.transform.localPosition.y <= -1){
|
|
target.transform.localPosition = new Vector3(target.transform.localPosition.x,-1f,target.transform.localPosition.z);
|
|
}
|
|
}
|
|
|
|
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"))
|
|
{
|
|
if (!uihandler.isPlayerInFight())
|
|
{
|
|
interact.transform.localScale = new Vector3(1, 1, 1);
|
|
}
|
|
}
|
|
switch (obj.ToLower())
|
|
{
|
|
case "tree":
|
|
displayInformation(TextHandler.getText("tree"));
|
|
break;
|
|
case "stone":
|
|
displayInformation(TextHandler.getText("rock"));
|
|
break;
|
|
case "npc":
|
|
displayInformation("NPC");
|
|
break;
|
|
case "enemy":
|
|
displayInformation(TextHandler.translate(hit.collider.gameObject.GetComponent<Enemy>().getEnemyName()));
|
|
break;
|
|
case "house":
|
|
displayInformation(TextHandler.getText("house"));
|
|
break;
|
|
case "door":
|
|
displayInformation(TextHandler.getText("door"));
|
|
break;
|
|
case "chest":
|
|
displayInformation(TextHandler.getText("chest"));
|
|
break;
|
|
case "ore":
|
|
if (hit.collider.gameObject.name.ToLower().Contains("iron"))
|
|
{
|
|
displayInformation(TextHandler.translate("Iron ore"));
|
|
}
|
|
else if (hit.collider.gameObject.name.ToLower().Contains("gold"))
|
|
{
|
|
displayInformation(TextHandler.translate("Gold ore"));
|
|
}
|
|
else if (hit.collider.gameObject.name.ToLower().Contains("copper"))
|
|
{
|
|
displayInformation(TextHandler.translate("Copper ore"));
|
|
}
|
|
else if (hit.collider.gameObject.name.ToLower().Contains("tin"))
|
|
{
|
|
displayInformation(TextHandler.translate("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();
|
|
}
|
|
}
|
|
}
|
|
} |