ClickSpawn.cs 528 B

123456789101112131415161718192021222324252627282930
  1. using UnityEngine;
  2. using System.Collections;
  3. public class ClickSpawn : MonoBehaviour {
  4. public GameObject Effect;
  5. void Start () {
  6. }
  7. void Update () {
  8. if (Input.GetButtonDown ("Fire1"))
  9. {
  10. StartCoroutine("Spawner");
  11. }
  12. }
  13. IEnumerator Spawner()
  14. {
  15. var mousePos = Input.mousePosition;
  16. // mousePos.y = 0.25f;
  17. mousePos.z = 5f;
  18. var objectPos = Camera.main.ScreenToWorldPoint(mousePos);
  19. Instantiate(Effect, objectPos, Quaternion.identity);
  20. yield return new WaitForSeconds(1);
  21. //Destroy (Effect);
  22. }
  23. }