Created
August 26, 2013 22:08
-
-
Save gabrielstuff/6347267 to your computer and use it in GitHub Desktop.
Spawning particles around x,y on a particular Z plan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using TouchScript.Gestures; | |
using UnityEngine; | |
using System.Collections; | |
public class SpawnSparkle : MonoBehaviour | |
{ | |
public Transform Container; | |
public GameObject ParticlePrefab; | |
[Range(0.0f, 100)] | |
public float zPosition; | |
[Range(0.0f, 500)] | |
public float factor; | |
private void Start() | |
{ | |
GetComponent<PressGesture>().StateChanged += HandleStateChanged; | |
} | |
private void HandleStateChanged(object sender, TouchScript.Events.GestureStateChangeEventArgs e) | |
{ | |
if (e.State == Gesture.GestureState.Recognized) | |
{ | |
var gesture = sender as PressGesture; | |
RaycastHit hit; | |
gesture.GetTargetHitResult(out hit); | |
Vector3 camPos = Camera.main.transform.position; | |
Ray ray = new Ray(camPos, hit.point - camPos); | |
var particleSpark = (GameObject)Instantiate(ParticlePrefab, transform.localScale, Quaternion.identity); | |
particleSpark.transform.parent = Container.transform; | |
particleSpark.name = "Sparkle-" + gesture.ActiveTouches[0].Id; | |
particleSpark.transform.position = ray.GetPoint(zPosition); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment