Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. public class PlayerShooting : MonoBehaviour
  2. {
  3. [SerializeField]
  4. float ShootingSpeed = 2f;
  5.  
  6. [SerializeField]
  7. GameObject BulletPrefab;
  8.  
  9. [SerializeField]
  10. Vector2 ShootPoint;
  11.  
  12.  
  13. void Start()
  14. {
  15.  
  16. }
  17.  
  18.  
  19. void Update()
  20. {
  21. if (Input.GetMouseButtonDown(0))
  22. Shoot();
  23.  
  24.  
  25.  
  26. }
  27.  
  28. void Shoot()
  29. {
  30. var bullet = Instantiate(BulletPrefab);
  31. bullet.transform.position = transform.position + transform.rotation *(Vector3)ShootPoint;
  32. bullet.transform.rotation = transform.rotation;
  33.  
  34. var bulletRigidbody = bullet.GetComponent<Rigidbody2D>();
  35. bulletRigidbody.velocity = transform.right * ShootingSpeed;
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement