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 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(); 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("Tree"); break; case "stone": displayInformation("Rock"); break; case "npc": displayInformation("NPC"); break; case "enemy": displayInformation(hit.collider.gameObject.GetComponent().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(); } } } }