使用射线单击物体显示,点击物体隐藏
// 检测鼠标左键的点击事件
if (Input.GetMouseButtonUp(0))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); // 创建射线从相机指向鼠标点击位置
if (Physics.Raycast(ray, out hit)) // 如果射线击中了物体
{
GameObject clickedObject = hit.transform.gameObject; // 获取被点击的物体
if (clickedObject.name == "Left") //第一排左
{
if ((!ModelAir_Animal[1].activeSelf) || (!ModelAir_Animal[0].activeSelf))
{
//传递给安卓为true
AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(1, true);
Debug.Log("打开Left:" + ModelAir_Animal[1].activeSelf);
}
if (ModelAir_Animal[1].activeSelf && ModelAir_Animal[0].activeSelf)
{
//传递给安卓为false
AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(1, false);
Debug.Log("关闭Left:" + ModelAir_Animal[1].activeSelf);
}
}
if (clickedObject.name == "MiddleLeft") //第一排左中
{
if ((!ModelAir_Animal[2].activeSelf) || (!ModelAir_Animal[0].activeSelf))
{
//传递给安卓为true
AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(3, true);
Debug.Log("打开MiddleLeft:" + ModelAir_Animal[2].activeSelf);
}
if (ModelAir_Animal[2].activeSelf && ModelAir_Animal[0].activeSelf)
{
//传递给安卓为false
AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(3, false);
Debug.Log("关闭MiddleLeft:" + ModelAir_Animal[2].activeSelf);
}
}
if (clickedObject.name == "MiddleRight") //第一排右中
{
if ((!ModelAir_Animal[4].activeSelf) || (!ModelAir_Animal[0].activeSelf))
{
//传递给安卓为true
AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(6, true);
Debug.Log("打开MiddleRight:" + ModelAir_Animal[4].activeSelf);
}
if (ModelAir_Animal[4].activeSelf && ModelAir_Animal[0].activeSelf)
{
//传递给安卓为false
AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(6, false);
Debug.Log("关闭MiddleRight:" + ModelAir_Animal[4].activeSelf);
}
}
if (clickedObject.name == "Right") //第一排右
{
if ((!ModelAir_Animal[3].activeSelf) || (!ModelAir_Animal[0].activeSelf))
{
//传递给安卓为true
AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(4, true);
Debug.Log("打开Right:" + ModelAir_Animal[3].activeSelf);
}
if (ModelAir_Animal[3].activeSelf && ModelAir_Animal[0].activeSelf)
{
//传递给安卓为false
AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(4, false);
Debug.Log("关闭Right:" + ModelAir_Animal[3].activeSelf);
}
}
if (clickedObject.name == "Defrost") //第一排窗
{
if ((!ModelAir_Animal[5].activeSelf) || (!ModelAir_Animal[0].activeSelf))
{
//传递给安卓为true
AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(7, true);
Debug.Log("打开Defrost:" + ModelAir_Animal[5].activeSelf);
}
if (ModelAir_Animal[5].activeSelf && ModelAir_Animal[0].activeSelf)
{
//传递给安卓为false
AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(7, false);
Debug.Log("关闭Defrost:" + ModelAir_Animal[5].activeSelf);
}
}
if (clickedObject.name == "LeftLeg") //第一排左腿
{
if ((!ModelAir_Animal[6].activeSelf) || (!ModelAir_Animal[0].activeSelf))
{
//传递给安卓为true
AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(2, true);
Debug.Log("打开LeftLeg:" + ModelAir_Animal[6].activeSelf);
}
if (ModelAir_Animal[6].activeSelf && ModelAir_Animal[0].activeSelf)
{
//传递给安卓为false
AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(2, false);
Debug.Log("关闭LeftLeg:" + ModelAir_Animal[6].activeSelf);
}
}
if (clickedObject.name == "RightLeg") //第一排右腿
{
if ((!ModelAir_Animal[7].activeSelf) || (!ModelAir_Animal[0].activeSelf))
{
//传递给安卓为true
AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(5, true);
Debug.Log("打开RightLeg:" + ModelAir_Animal[7].activeSelf);
}
if (ModelAir_Animal[7].activeSelf && ModelAir_Animal[0].activeSelf)
{
//传递给安卓为false
AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(5, false);
Debug.Log("关闭RightLeg:" + ModelAir_Animal[7].activeSelf);
}
}
if (clickedObject.name == "SecondLeft") //第二排左
{
if ((!ModelAir_Animal[8].activeSelf) || (!ModelAir_Animal[12].activeSelf))
{
//传递给安卓为true
AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(16, true);
Debug.Log("打开SecondLeft:" + ModelAir_Animal[8].activeSelf);
}
if (ModelAir_Animal[8].activeSelf && ModelAir_Animal[12].activeSelf)
{
//传递给安卓为false
AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(16, false);
Debug.Log("关闭SecondLeft:" + ModelAir_Animal[8].activeSelf);
}
}
if (clickedObject.name == "SecondRight") //第二排右
{
if ((!ModelAir_Animal[9].activeSelf) || (!ModelAir_Animal[12].activeSelf))
{
//传递给安卓为true
AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(64, true);
Debug.Log("打开SecondRight:" + ModelAir_Animal[9].activeSelf);
}
if (ModelAir_Animal[9].activeSelf && ModelAir_Animal[12].activeSelf)
{
//传递给安卓为false
AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(64, false);
Debug.Log("关闭SecondRight:" + ModelAir_Animal[9].activeSelf);
}
}
if (clickedObject.name == "SecondLeftLeg") //第二排左腿
{
if ((!ModelAir_Animal[10].activeSelf) || (!ModelAir_Animal[12].activeSelf))
{
//传递给安卓为true
AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(17, true);
Debug.Log("打开SecondLeftLeg:" + ModelAir_Animal[10].activeSelf);
}
if (ModelAir_Animal[10].activeSelf && ModelAir_Animal[12].activeSelf)
{
//传递给安卓为false
AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(17, false);
Debug.Log("关闭SecondLeftLeg:" + ModelAir_Animal[10].activeSelf);
}
}
if (clickedObject.name == "SecondRightLeg") //第二排右腿
{
if ((!ModelAir_Animal[11].activeSelf) || (!ModelAir_Animal[12].activeSelf))
{
//传递给安卓为true
AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(65, true);
Debug.Log("打开SecondRightLeg:" + ModelAir_Animal[11].activeSelf);
}
if (ModelAir_Animal[11].activeSelf && ModelAir_Animal[12].activeSelf)
{
//传递给安卓为false
AndroidMessage.ins.getUnityCallFunction()?.ElectricalStatusToggle(65, false);
Debug.Log("关闭SecondRightLeg:" + ModelAir_Animal[11].activeSelf);
}
}
}