背包摆放陶瓷原料的操作

master
LeeNux 2 years ago
parent 75ab7e5ddd
commit 155ed2046f

File diff suppressed because it is too large Load Diff

@ -0,0 +1,37 @@
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class SetItem : MonoBehaviour
{
public int i = 0;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private void OnTriggerStay(Collider collision)
{
// Debug.Log(collision.gameObject.name);
Camera.main.GetComponent<Player>().Hp -= Time.deltaTime;
Camera.main.GetComponent<Player>().SetHp();
}
private void OnTriggerEnter(Collider collision)
{
Camera.main.GetComponent<Player>().inTarget = true;
}
private void OnTriggerExit(Collider collision)
{
Camera.main.GetComponent<Player>().inTarget = false;
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6d92369e002efaf498dc21efc50e777a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -8,9 +8,14 @@ using TMPro;
public class Player : MonoBehaviour
{
public int MaxHp = 100;
public int Hp = 10;
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()
{
@ -20,13 +25,27 @@ public class Player : MonoBehaviour
public void SetHp() {
HpBar.GetComponent<Slider>().value = Hp;
//Debug.Log(HpBar.GetComponentInChildren<TextMeshPro>().text);
HpText.GetComponent<TextMeshProUGUI>().SetText(Hp + "/" + MaxHp);
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;
}
}

@ -1,18 +1,40 @@
using StarterAssets;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TakeItem : MonoBehaviour
{
// Start is called before the first frame update
void Start()
public GameObject ui;
public GameObject box;
public GameObject bag;
public GameObject Player;
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player") {
ui.SetActive(true);
}
}
// Update is called once per frame
void Update()
private void OnTriggerExit(Collider other)
{
if (other.gameObject.tag == "Player")
{
ui.SetActive(false);
box.SetActive(false);
}
}
private void OnTriggerStay(Collider other)
{
if(Input.GetKeyDown(KeyCode.E))
{
box.SetActive(!box.activeInHierarchy);
if(box.activeInHierarchy)
{
bag.SetActive(true);
}
}
}
}

@ -1,27 +1,49 @@
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class item : MonoBehaviour
{
public bool inBox = true;
public GameObject target;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void pick() {
public void pick()
{
if (inBox)
{
transform.parent = GameObject.Find("Bag").transform;
transform.SetParent(GameObject.Find("Bag").transform);
inBox = false;
}
else
{
if(Camera.main.GetComponent<Player>().inTarget) {
int i = target.GetComponent<SetItem>().i;
if(i<= target.transform.childCount)
{
target.transform.GetChild(i).gameObject.SetActive(true);
target.GetComponent<SetItem>().i=i+1;
gameObject.SetActive(false);
}
}
}
}
}

Loading…
Cancel
Save