Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //in player behaviour
- public GameObject bulletPrefab;
- public float bulletSpeed = 100;
- private bool isShooting;
- void Update() {
- isShooting |= Input.GetKeyDown(KeyCode.Space);
- }
- private void FixedUpdate() {
- if (isShooting)
- {
- GameObject bullet = Instantiate(bulletPrefab, transform.position + transform.forward, transform.rotation);
- Rigidbody bulletRB = bullet.GetComponent<Rigidbody>();
- bulletRB.velocity = transform.forward * bulletSpeed;
- }
- isShooting = false;
- }
- //in bullet behaviour and attached to bullet prefab
- public class BulletBehaviour : MonoBehaviour
- {
- public float onScreenTime = 3;
- void Start() {
- Destroy(gameObject, onScreenTime);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement