Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class gunShooting : MonoBehaviour
  6. {
  7. public playerControls _playerControls;//reference to playerControls script on player
  8. public GameObject _bulletPrefab;//prefab of object were going to spawn
  9. public Transform _bulletSpawnPoint;//position of where to spawn bullets to map
  10. public float bulletSpeed;//speed of bullets on shoot
  11.  
  12. public void Shoot()
  13. {
  14. // Debug.Log("bullet shot,spawned and moved kill it later");
  15. GameObject bullet = GameObject.Instantiate(_bulletPrefab, _bulletSpawnPoint.position, Quaternion.identity);//instantiate script to spawn bullet
  16. bullet.GetComponent<Rigidbody>().AddForce(this.transform.forward * bulletSpeed, ForceMode.Impulse);//add force function to move bullet
  17. }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement