Projectile.cs 679 B

12345678910111213141516171819202122232425262728293031
  1. using UnityEngine;
  2. using UnityEngine.InputSystem;
  3. public class Projectile : MonoBehaviour
  4. {
  5. public GameManager gameManager;
  6. public float speed = 1;
  7. public Vector3 direction = Vector3.zero;
  8. // Start is called once before the first execution of Update after the MonoBehaviour is created
  9. void Start()
  10. {
  11. if (gameManager == null)
  12. {
  13. gameManager = FindFirstObjectByType<GameManager>();
  14. }
  15. }
  16. // Update is called once per frame
  17. void Update()
  18. {
  19. transform.position = transform.position + direction.normalized * speed;
  20. }
  21. public void SetValues(float speed, Vector3 direction)
  22. {
  23. this.speed = speed;
  24. this.direction = direction;
  25. }
  26. }