Pistol Asset
This commit is contained in:
1 parent
fedfa54457
commit
c833971016
98 files changed
+17924
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 11c5769b733014f458c6c86a10e5613f
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,92 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[AddComponentMenu("Nokobot/Modern Guns/Simple Shoot")]
|
||||
public class SimpleShoot : MonoBehaviour
|
||||
{
|
||||
[Header("Prefab Refrences")]
|
||||
public GameObject bulletPrefab;
|
||||
public GameObject casingPrefab;
|
||||
public GameObject muzzleFlashPrefab;
|
||||
|
||||
[Header("Location Refrences")]
|
||||
[SerializeField] private Animator gunAnimator;
|
||||
[SerializeField] private Transform barrelLocation;
|
||||
[SerializeField] private Transform casingExitLocation;
|
||||
|
||||
[Header("Settings")]
|
||||
[Tooltip("Specify time to destory the casing object")][SerializeField] private float destroyTimer = 2f;
|
||||
[Tooltip("Bullet Speed")][SerializeField] private float shotPower = 500f;
|
||||
[Tooltip("Casing Ejection Speed")][SerializeField] private float ejectPower = 150f;
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (barrelLocation == null)
|
||||
barrelLocation = transform;
|
||||
|
||||
if (gunAnimator == null)
|
||||
gunAnimator = GetComponentInChildren<Animator>();
|
||||
}
|
||||
|
||||
/*
|
||||
void Update()
|
||||
{
|
||||
//If you want a different input, change it here
|
||||
if (Input.GetButtonDown("Fire1"))
|
||||
{
|
||||
//Calls animation on the gun that has the relevant animation events that will fire
|
||||
gunAnimator.SetTrigger("Fire");
|
||||
}
|
||||
}
|
||||
*/
|
||||
public void StartShoot()
|
||||
{
|
||||
gunAnimator.SetTrigger("Fire");
|
||||
|
||||
}
|
||||
|
||||
|
||||
//This function creates the bullet behavior
|
||||
void Shoot()
|
||||
{
|
||||
if (muzzleFlashPrefab)
|
||||
{
|
||||
//Create the muzzle flash
|
||||
GameObject tempFlash;
|
||||
tempFlash = Instantiate(muzzleFlashPrefab, barrelLocation.position, barrelLocation.rotation);
|
||||
|
||||
//Destroy the muzzle flash effect
|
||||
Destroy(tempFlash, destroyTimer);
|
||||
}
|
||||
|
||||
//cancels if there's no bullet prefeb
|
||||
if (!bulletPrefab)
|
||||
{ return; }
|
||||
|
||||
// Create a bullet and add force on it in direction of the barrel
|
||||
Instantiate(bulletPrefab, barrelLocation.position, barrelLocation.rotation).GetComponent<Rigidbody>().AddForce(barrelLocation.forward * shotPower);
|
||||
|
||||
}
|
||||
|
||||
//This function creates a casing at the ejection slot
|
||||
void CasingRelease()
|
||||
{
|
||||
//Cancels function if ejection slot hasn't been set or there's no casing
|
||||
if (!casingExitLocation || !casingPrefab)
|
||||
{ return; }
|
||||
|
||||
//Create the casing
|
||||
GameObject tempCasing;
|
||||
tempCasing = Instantiate(casingPrefab, casingExitLocation.position, casingExitLocation.rotation) as GameObject;
|
||||
//Add force on casing to push it out
|
||||
tempCasing.GetComponent<Rigidbody>().AddExplosionForce(Random.Range(ejectPower * 0.7f, ejectPower), (casingExitLocation.position - casingExitLocation.right * 0.3f - casingExitLocation.up * 0.6f), 1f);
|
||||
//Add torque to make casing spin in random direction
|
||||
tempCasing.GetComponent<Rigidbody>().AddTorque(new Vector3(0, Random.Range(100f, 500f), Random.Range(100f, 1000f)), ForceMode.Impulse);
|
||||
|
||||
//Destroy casing after X seconds
|
||||
Destroy(tempCasing, destroyTimer);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6be84e4d7829855419c06b94e56bd135
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in new issue
Block a user