using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using StarterAssets; using TMPro; public class Player : MonoBehaviour { public int MaxHp = 100; public float Hp = 10; public GameObject HpBar; public GameObject HpText; public GameObject PlayerObj; public bool inTarget = false; public GameObject Bag; // Start is called before the first frame update void Start() { SetHp(); } public void SetHp() { HpBar.GetComponent().value = Hp; //Debug.Log(HpBar.GetComponentInChildren().text); HpText.GetComponent().SetText(Hp.ToString("F2") + "/" + MaxHp); } // Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.F)) { Bag.SetActive(!Bag.activeInHierarchy); } if(Bag.activeInHierarchy) { PlayerObj.GetComponent().cursorLocked = false; PlayerObj.GetComponent().cursorInputForLook = false; Cursor.visible = true; } else { PlayerObj.GetComponent().cursorLocked = true; PlayerObj.GetComponent().cursorInputForLook = true; } } }