added font, updated ui, fixed some code
This commit is contained in:
142
Assets/Scripts/Player/PlayerCamera.cs
Normal file
142
Assets/Scripts/Player/PlayerCamera.cs
Normal file
@@ -0,0 +1,142 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Assets.Scripts.Player
|
||||
{
|
||||
public class PlayerCamera : MonoBehaviour
|
||||
{
|
||||
UIHandler uihandler;
|
||||
GameObject player;
|
||||
Vector2 rotation = Vector2.zero;
|
||||
public float mouseSpeed = 1; //the sensibility
|
||||
public float controllerSpeed = 0.01f; //the sensibility
|
||||
float xMaxLimit = 50.0f;
|
||||
float xMinLimit = -50.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()
|
||||
{
|
||||
transform.position = new Vector3(transform.parent.transform.position.x, transform.position.y, transform.parent.transform.position.z);
|
||||
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
showInformation();
|
||||
}
|
||||
|
||||
public void lookAround(Vector2 view, bool isController){
|
||||
rotation.y += view.x;
|
||||
rotation.x += -view.y;
|
||||
rotation.x = Mathf.Clamp(rotation.x, xMinLimit, xMaxLimit);
|
||||
if(isController){
|
||||
transform.eulerAngles = (Vector2)rotation * controllerSpeed;
|
||||
}
|
||||
else{
|
||||
transform.eulerAngles = (Vector2)rotation * mouseSpeed;
|
||||
}
|
||||
}
|
||||
|
||||
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(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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user