天津23维预案
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.
 
 
 
 
 
 

66 lines
2.2 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class CreateXHS : MonoBehaviour {
/// <summary>
/// 创建消火栓
/// </summary>
private RaycastHit hit;//射线
public LayerMask ground_layerMask = -1;
public static CreateXHS instance = null;
private Toggle toggle;
void Awake ()
{
if (instance == null)
{
instance = this;
}
}
private void Start()
{
toggle = this.GetComponent<Toggle>();
toggle.onValueChanged.AddListener(ChangeValue);
}
public void ChangeValue(bool flag)
{
if (flag)
{
ControlInstance = true;
}
else
{
ControlInstance = false;
}
}
bool ControlInstance = false;
public List<GameObject> XHSList = new List<GameObject>();
void Update()
{
if (ControlInstance)
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, Mathf.Infinity, ground_layerMask) && Input.GetMouseButtonDown(0) &&
!EventSystem.current.IsPointerOverGameObject())
{
GameObject xhs = Instantiate(Resources.Load<GameObject>("Prefabs/ToolPrefab/XHSScene"));
xhs.transform.parent = GameObject.Find("AllParent/pXhs").transform;
xhs.transform.localPosition = hit.point+new Vector3(0,0.5f,0);
xhs.transform.localScale = new Vector3(1.8f, 1.8f, 1.8f);
xhs.GetComponent<CengID>().cengID = hit.transform.GetComponent<CengID>().cengID;
xhs.GetComponent<CengID>().CengIDBuildType = hit.transform.GetComponent<CengID>().CengIDBuildType;
string Now = System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString() + System.DateTime.Now.Day.ToString() + System.DateTime.Now.Hour.ToString() + System.DateTime.Now.Minute.ToString() + System.DateTime.Now.Second.ToString()+ System.DateTime.Now.Millisecond.ToString();
xhs.name = "XHSScene" + Now;
XHSList.Add(xhs);
}
}
}
}