PolygonFireProjectile.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using UnityEngine;
  2. using UnityEngine.EventSystems;
  3. using System.Collections;
  4. namespace PolygonArsenal
  5. {
  6. public class PolygonFireProjectile : MonoBehaviour
  7. {
  8. RaycastHit hit;
  9. public GameObject[] projectiles;
  10. public Transform spawnPosition;
  11. [HideInInspector]
  12. public int currentProjectile = 0;
  13. public float speed = 1000;
  14. // MyGUI _GUI;
  15. PolygonButtonScript selectedProjectileButton;
  16. void Start()
  17. {
  18. selectedProjectileButton = GameObject.Find("Button").GetComponent<PolygonButtonScript>();
  19. }
  20. void Update()
  21. {
  22. if (Input.GetKeyDown(KeyCode.RightArrow))
  23. {
  24. nextEffect();
  25. }
  26. if (Input.GetKeyDown(KeyCode.D))
  27. {
  28. nextEffect();
  29. }
  30. if (Input.GetKeyDown(KeyCode.A))
  31. {
  32. previousEffect();
  33. }
  34. else if (Input.GetKeyDown(KeyCode.LeftArrow))
  35. {
  36. previousEffect();
  37. }
  38. if (Input.GetKeyDown(KeyCode.Mouse0))
  39. {
  40. if (!EventSystem.current.IsPointerOverGameObject())
  41. {
  42. if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100f))
  43. {
  44. GameObject projectile = Instantiate(projectiles[currentProjectile], spawnPosition.position, Quaternion.identity) as GameObject;
  45. projectile.transform.LookAt(hit.point);
  46. projectile.GetComponent<Rigidbody>().AddForce(projectile.transform.forward * speed);
  47. }
  48. }
  49. }
  50. Debug.DrawRay(Camera.main.ScreenPointToRay(Input.mousePosition).origin, Camera.main.ScreenPointToRay(Input.mousePosition).direction * 100, Color.yellow);
  51. }
  52. public void nextEffect()
  53. {
  54. if (currentProjectile < projectiles.Length - 1)
  55. currentProjectile++;
  56. else
  57. currentProjectile = 0;
  58. selectedProjectileButton.getProjectileNames();
  59. }
  60. public void previousEffect()
  61. {
  62. if (currentProjectile > 0)
  63. currentProjectile--;
  64. else
  65. currentProjectile = projectiles.Length - 1;
  66. selectedProjectileButton.getProjectileNames();
  67. }
  68. public void AdjustSpeed(float newSpeed)
  69. {
  70. speed = newSpeed;
  71. }
  72. }
  73. }