40 lines
1.0 KiB
C#
40 lines
1.0 KiB
C#
using UnityEngine;
|
|
|
|
public class PPFXSpawnOnClick : MonoBehaviour
|
|
{
|
|
public GameObject inst;
|
|
|
|
public string tagName;
|
|
|
|
private GameObject container;
|
|
|
|
private void Start()
|
|
{
|
|
container = new GameObject();
|
|
container.name = "_Container";
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (!Input.GetMouseButtonDown(0) && Input.touchCount <= 0)
|
|
{
|
|
return;
|
|
}
|
|
Ray ray = ((Application.platform != RuntimePlatform.Android) ? Camera.main.ScreenPointToRay(Input.mousePosition) : Camera.main.ScreenPointToRay(Input.GetTouch(0).position));
|
|
RaycastHit hitInfo;
|
|
if (Physics.Raycast(ray, out hitInfo) && GUIUtility.hotControl == 0 && hitInfo.collider.tag == tagName && inst != null)
|
|
{
|
|
Vector3 position = new Vector3(hitInfo.point.x, 0f, hitInfo.point.z);
|
|
GameObject gameObject = Object.Instantiate(inst, position, inst.transform.rotation);
|
|
if (container != null)
|
|
{
|
|
gameObject.transform.parent = container.transform;
|
|
return;
|
|
}
|
|
container = new GameObject();
|
|
container.name = "_Container";
|
|
gameObject.transform.parent = container.transform;
|
|
}
|
|
}
|
|
}
|