mirror of
https://github.com/noakdsv/AtomCraft-2.28.git
synced 2024-10-22 23:44:19 +02:00
117 lines
3.3 KiB
C#
117 lines
3.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class MenuManager : MonoBehaviour
|
|
{
|
|
private GameObject carbon;
|
|
private GameObject lithium;
|
|
private GameObject hydrogen;
|
|
public int targetPro = 0;
|
|
public int targetNue = 0;
|
|
public int targetEle = 0;
|
|
|
|
public GameObject calculator;
|
|
|
|
public Atom atom;
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
// 在Start方法中查找子对象并分配给相应的变量
|
|
foreach (Transform child in transform)
|
|
{
|
|
if (child.name == "Carbon")
|
|
carbon = child.gameObject;
|
|
else if (child.name == "Lithium")
|
|
lithium = child.gameObject;
|
|
else if (child.name == "Hydrogen")
|
|
hydrogen = child.gameObject;
|
|
}
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (Input.touchCount > 0)
|
|
{
|
|
Touch touch = Input.GetTouch(0);
|
|
if (touch.phase == TouchPhase.Began)
|
|
{
|
|
Vector3 touchPosition = Camera.main.ScreenToWorldPoint(touch.position);
|
|
touchPosition.z = 0;
|
|
|
|
// 检测按钮1是否与触摸位置发生碰撞
|
|
if (carbon != null && carbon.GetComponent<Collider2D>().OverlapPoint(touchPosition))
|
|
{
|
|
Debug.Log("Player pressed Carbon!");
|
|
// 在这里添加按钮1被触摸时的操作
|
|
targetPro = 6;
|
|
targetNue = 6;
|
|
targetEle = 6;
|
|
|
|
|
|
}
|
|
|
|
// 检测按钮2是否与触摸位置发生碰撞
|
|
if (lithium != null && lithium.GetComponent<Collider2D>().OverlapPoint(touchPosition))
|
|
{
|
|
Debug.Log("Player pressed Lithium!");
|
|
// 在这里添加按钮2被触摸时的操作
|
|
targetPro = 3;
|
|
targetNue = 4;
|
|
targetEle = 3;
|
|
}
|
|
|
|
// 检测按钮3是否与触摸位置发生碰撞
|
|
if (hydrogen != null && hydrogen.GetComponent<Collider2D>().OverlapPoint(touchPosition))
|
|
{
|
|
Debug.Log("Player pressed Hydrogen!");
|
|
// 在这里添加按钮3被触摸时的操作
|
|
targetPro = 1;
|
|
targetNue = 0;
|
|
targetEle = 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void AtomButtonPressed(string atomName)
|
|
{
|
|
calculator.SetActive(true);
|
|
|
|
if (atomName == "Hydrogen")
|
|
{
|
|
Debug.Log("Player pressed Hydrogen!");
|
|
targetPro = 1;
|
|
targetNue = 0;
|
|
targetEle = 1;
|
|
|
|
atom.SetElementName("Hydrogen");
|
|
}
|
|
else if (atomName == "Lithium")
|
|
{
|
|
Debug.Log("Player pressed Lithium!");
|
|
targetPro = 3;
|
|
targetNue = 4;
|
|
targetEle = 3;
|
|
|
|
atom.SetElementName("Lithium");
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("Player pressed Carbon!");
|
|
targetPro = 6;
|
|
targetNue = 6;
|
|
targetEle = 6;
|
|
|
|
atom.SetElementName("Carbon");
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} |