GunController.cs 821 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using UnityEngine;
  2. using UnityEngine.InputSystem;
  3. public class GunController : MonoBehaviour
  4. {
  5. [SerializeField]
  6. private Transform muzzle;
  7. [SerializeField]
  8. private InputActionProperty Trigger;
  9. public float shotsPerSecond = 1.0f;
  10. public float projectileSpeed = 1.0f;
  11. public GameObject projectileObject;
  12. // Start is called once before the first execution of Update after the MonoBehaviour is created
  13. void Start()
  14. {
  15. }
  16. // Update is called once per frame
  17. void Update()
  18. {
  19. if (Trigger.action.IsPressed())
  20. {
  21. GameObject spawnedObject = Instantiate(projectileObject);
  22. Projectile projectileScript = spawnedObject.GetComponent<Projectile>();
  23. if (projectileScript != null) {
  24. projectileScript.Direction = Vector3.up;
  25. }
  26. Debug.Log("Shoot");
  27. }
  28. }
  29. }