SFE_effectCaster.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //This is responsible that the cursor follows the mouse, and that an effect plays if the user clicks
  2. // also this script handles changing the effects.
  3. var moveThis : GameObject; //this is an invisible "cursor" that is always there where the mouse points
  4. var camRoot:GameObject;
  5. var camPoint1:GameObject;
  6. var camPoint2:GameObject;
  7. private var camCurrent:int=1;
  8. var spaceShip : GameObject;
  9. private var hit : RaycastHit;
  10. var createThis : GameObject[];
  11. private var cooldown : float;
  12. private var changeCooldown : float;
  13. private var selected:int=0;
  14. var writeThis:GUIText;
  15. private var rndNr:float;
  16. private var effect:GameObject;
  17. var layermask:LayerMask;
  18. function Start () {
  19. selected=createThis.length-1;
  20. writeThis.text=selected.ToString()+" "+createThis[selected].name;
  21. }
  22. function Update () {
  23. if(cooldown>0){cooldown-=Time.deltaTime;}
  24. if(changeCooldown>0){changeCooldown-=Time.deltaTime;}
  25. var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
  26. if (Physics.Raycast (ray, hit, 1000, layermask)) {
  27. moveThis.transform.position=hit.point;
  28. if(Input.GetMouseButton(0)&&cooldown<=0){
  29. effect=Instantiate(createThis[selected], spaceShip.transform.position, spaceShip.transform.rotation);
  30. effect.transform.parent=spaceShip.transform;
  31. cooldown=0.5;
  32. }
  33. }
  34. if (Input.GetKeyDown(KeyCode.UpArrow) && changeCooldown<=0)
  35. {
  36. selected+=1;
  37. if(selected>(createThis.length-1)) {selected=0;}
  38. writeThis.text=selected.ToString()+" "+createThis[selected].name;
  39. changeCooldown=0.1;
  40. }
  41. if (Input.GetKeyDown(KeyCode.DownArrow) && changeCooldown<=0)
  42. {
  43. selected-=1;
  44. if(selected<0) {selected=createThis.length-1;}
  45. writeThis.text=selected.ToString()+" "+createThis[selected].name;
  46. changeCooldown=0.1;
  47. }
  48. if (Input.GetKeyDown(KeyCode.Space) && changeCooldown<=0)
  49. {
  50. if (camCurrent==1)
  51. {
  52. camCurrent=2;
  53. camRoot.transform.position=camPoint2.transform.position;
  54. camRoot.transform.rotation=camPoint2.transform.rotation;
  55. }
  56. else
  57. {
  58. camCurrent=1;
  59. camRoot.transform.position=camPoint1.transform.position;
  60. camRoot.transform.rotation=camPoint1.transform.rotation;
  61. }
  62. changeCooldown=0.1;
  63. }
  64. }