Skip to content

Instantly share code, notes, and snippets.

@DB-009
Created April 8, 2019 23:30
Show Gist options
  • Save DB-009/9c0bb3aa6008efefd5eeffd1d38e992e to your computer and use it in GitHub Desktop.
Save DB-009/9c0bb3aa6008efefd5eeffd1d38e992e to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class gunShooting : MonoBehaviour
{
public playerControls _playerControls;//reference to playerControls script on player
public GameObject _bulletPrefab;//prefab of object were going to spawn
public Transform _bulletSpawnPoint;//position of where to spawn bullets to map
public float bulletSpeed;//speed of bullets on shoot
public void Shoot()
{
// Debug.Log("bullet shot,spawned and moved kill it later");
GameObject bullet = GameObject.Instantiate(_bulletPrefab, _bulletSpawnPoint.position, Quaternion.identity);//instantiate script to spawn bullet
bullet.GetComponent<Rigidbody>().AddForce(this.transform.forward * bulletSpeed, ForceMode.Impulse);//add force function to move bullet
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment