Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PlayerShooting : MonoBehaviour
- {
- [SerializeField]
- float ShootingSpeed = 2f;
- [SerializeField]
- GameObject BulletPrefab;
- [SerializeField]
- Vector2 ShootPoint;
- void Start()
- {
- }
- void Update()
- {
- if (Input.GetMouseButtonDown(0))
- Shoot();
- }
- void Shoot()
- {
- var bullet = Instantiate(BulletPrefab);
- bullet.transform.position = transform.position + transform.rotation *(Vector3)ShootPoint;
- bullet.transform.rotation = transform.rotation;
- var bulletRigidbody = bullet.GetComponent<Rigidbody2D>();
- bulletRigidbody.velocity = transform.right * ShootingSpeed;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement