FTME01_ClickToSpawn.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #pragma strict
  2. var prefabName:GUIText;
  3. var particlePrefab : GameObject[];
  4. var particleNum : int = 0;
  5. private var effectPrefab : GameObject;
  6. function Update () {
  7. var mouseX = Input.mousePosition.x;
  8. var mouseY = Input.mousePosition.y;
  9. var ray = GetComponent.<Camera>().main.ScreenPointToRay (Vector3(mouseX,mouseY,0));
  10. var hit : RaycastHit;
  11. if (Physics.Raycast (ray, hit, 200)) {}
  12. if ( Input.GetMouseButtonDown(0) ){
  13. if(particleNum == 0){
  14. effectPrefab = Instantiate(particlePrefab[particleNum],
  15. new Vector3(hit.point.x,hit.point.y,hit.point.z), Quaternion.Euler(0,0,0));
  16. }
  17. if(particleNum >= 1 && particleNum <= 2){
  18. effectPrefab = Instantiate(particlePrefab[particleNum],
  19. new Vector3(hit.point.x,hit.point.y + 0.2,hit.point.z), Quaternion.Euler(0,0,0));
  20. }
  21. if(particleNum >= 3 && particleNum <= 7){
  22. effectPrefab = Instantiate(particlePrefab[particleNum],
  23. new Vector3(hit.point.x,hit.point.y + 1,hit.point.z), Quaternion.Euler(0,0,0));
  24. }
  25. if(particleNum >= 8){
  26. effectPrefab = Instantiate(particlePrefab[particleNum],
  27. new Vector3(hit.point.x,hit.point.y + 0.2,hit.point.z), Quaternion.Euler(0,0,0));
  28. }
  29. }
  30. if (Input.GetKeyDown(KeyCode.LeftArrow)){
  31. particleNum -= 1;
  32. if( particleNum < 0) {
  33. particleNum = particlePrefab.length-1;
  34. }
  35. }
  36. if (Input.GetKeyDown(KeyCode.RightArrow)){
  37. particleNum += 1;
  38. if(particleNum >(particlePrefab.length - 1)) {
  39. particleNum = 0;
  40. }
  41. }
  42. prefabName.text= particlePrefab[particleNum].name;
  43. }