45 lines
1.1 KiB
C#
45 lines
1.1 KiB
C#
/*
|
|
* @author Valentin Simonov / http://va.lent.in/
|
|
*/
|
|
|
|
using UnityEngine;
|
|
|
|
namespace TouchScript.Examples.RawInput
|
|
{
|
|
/// <exclude />
|
|
public class Spawner : MonoBehaviour
|
|
{
|
|
public GameObject Prefab;
|
|
|
|
private void OnEnable()
|
|
{
|
|
if (TouchManager.Instance != null)
|
|
{
|
|
TouchManager.Instance.PointersPressed += pointersPressedHandler;
|
|
}
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
if (TouchManager.Instance != null)
|
|
{
|
|
TouchManager.Instance.PointersPressed -= pointersPressedHandler;
|
|
}
|
|
}
|
|
|
|
private void spawnPrefabAt(Vector2 position)
|
|
{
|
|
var obj = Instantiate(Prefab) as GameObject;
|
|
obj.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(position.x, position.y, 10));
|
|
obj.transform.rotation = transform.rotation;
|
|
}
|
|
|
|
private void pointersPressedHandler(object sender, PointerEventArgs e)
|
|
{
|
|
foreach (var pointer in e.Pointers)
|
|
{
|
|
spawnPrefabAt(pointer.Position);
|
|
}
|
|
}
|
|
}
|
|
} |