You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.3 KiB

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<Slider>().value = Hp;
//Debug.Log(HpBar.GetComponentInChildren<TextMeshPro>().text);
HpText.GetComponent<TextMeshProUGUI>().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<StarterAssetsInputs>().cursorLocked = false;
PlayerObj.GetComponent<StarterAssetsInputs>().cursorInputForLook = false;
Cursor.visible = true;
}
else
{
PlayerObj.GetComponent<StarterAssetsInputs>().cursorLocked = true;
PlayerObj.GetComponent<StarterAssetsInputs>().cursorInputForLook = true;
}
}
}