This commit is contained in:
HH 2021-07-09 16:12:57 -07:00
Родитель c628c75f0e
Коммит c2bd265e42
8 изменённых файлов: 1 добавлений и 381 удалений

Просмотреть файл

@ -2,7 +2,7 @@
// <auto-generated>
// This code was auto-generated by com.unity.inputsystem:InputActionCodeGenerator
// version 1.1.0
// from Assets/ML-Agents/Examples/Dodgeball/Input/DodgeBallInputActions.inputactions
// from Assets/Dodgeball/Input/DodgeBallInputActions.inputactions
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.

Просмотреть файл

@ -1,213 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;
[RequireComponent(typeof(AudioSource))]
public class GunController : MonoBehaviour
{
public bool AllowKeyboardInput = true; //this mode ignores player input
public bool initialized; //has this robot been initialized
public KeyCode shootKey = KeyCode.J;
[Header("AUTOSHOOT")] public bool autoShootEnabled;
//SHOOTING RATE
[Header("SHOOTING RATE")]
public float shootingRate = .02f; //can shoot every shootingRate seconds. ex: .5 can shoot every .5 seconds
private float shootTimer;
public bool coolDownWait;
//PROJECTILES
[Header("PROJECTILE")]
public GameObject projectilePrefab;
public int numberOfProjectilesToPool = 25;
public Transform projectileOrigin; //the transform the projectile will originate from
// public List<Projectile> projectilePoolList = new List<Projectile>(); //projectiles to shoot
public List<Rigidbody> projectilePoolList = new List<Rigidbody>(); //projectiles to shoot
//FORCES
[Header("FORCES")]
public float forceToUse;
[Header("MUZZLE FLASH")]
public bool UseMuzzleFlash;
[Header("SOUND")]
public bool PlaySound;
public ForceMode forceMode;
public GunSFX GunSFX;
private AudioSource m_AudioSource;
[Header("SCREEN SHAKE")]
public bool UseScreenShake;
[Header("TRANSFORM SHAKE")] public bool ShakeTransform;
public float ShakeDuration = .1f;
public float ShakeAmount = .1f;
private Vector3 startPos;
private bool m_TransformIsShaking;
CinemachineImpulseSource impulseSource;
public GameObject MuzzleFlashObject;
// Start is called before the first frame update
void Awake()
{
if (!initialized)
{
Initialize();
}
}
void OnEnable()
{
if (!initialized)
{
Initialize();
}
}
void Initialize()
{
projectilePoolList.Clear(); //clear list in case it's not empty
for (var i = 0; i < numberOfProjectilesToPool; i++)
{
impulseSource = GetComponent<CinemachineImpulseSource>();
GameObject obj = Instantiate(projectilePrefab, transform.position, Quaternion.identity);
Rigidbody p = obj.GetComponent<Rigidbody>();
projectilePoolList.Add(p);
p.transform.position = projectileOrigin.position;
// p.projectileController = this;
p.gameObject.SetActive(false);
}
if (MuzzleFlashObject)
{
MuzzleFlashObject.SetActive(false);
}
m_AudioSource = GetComponent<AudioSource>();
initialized = true;
}
void Update()
{
if (!AllowKeyboardInput)
{
return;
}
if (Input.GetKeyDown(shootKey))
{
Shoot();
// ShootQuantity(1);
}
}
void FixedUpdate()
{
coolDownWait = shootTimer > shootingRate ? false : true;
shootTimer += Time.fixedDeltaTime;
if (autoShootEnabled)
{
Shoot();
}
}
// public void ShootQuantity(int num)
// {
// var i = 0;
// while (i < num)
// {
// //shoot first available projectile in the pool
// foreach (var item in projectilePoolList)
// {
// if (!item.gameObject.activeInHierarchy)
// {
// FireProjectile(item.rb);
// impulseSource.GenerateImpulse();
// break;
// }
// }
//
// i++;
// }
// }
public void Shoot()
{
if (coolDownWait || !gameObject.activeSelf)
{
return;
}
shootTimer = 0; //reset timer
//shoot first available projectile in the pool
foreach (var item in projectilePoolList)
{
if (!item.gameObject.activeInHierarchy)
{
FireProjectile(item);
// FireProjectile(item.rb);
break;
}
}
}
public void FireProjectile(Rigidbody rb)
{
rb.transform.position = projectileOrigin.position;
rb.transform.rotation = projectileOrigin.rotation;
// rb.position = projectileOrigin.position;
// rb.rotation = projectileOrigin.rotation;
rb.velocity = Vector3.zero;
rb.angularVelocity = Vector3.zero;
rb.gameObject.SetActive(true);
rb.AddForce(projectileOrigin.forward * forceToUse, forceMode);
if (UseScreenShake && impulseSource)
{
impulseSource.GenerateImpulse();
}
if (ShakeTransform && !m_TransformIsShaking)
{
StartCoroutine(I_ShakeTransform());
}
if (PlaySound)
{
m_AudioSource.PlayOneShot(m_AudioSource.clip);
// GunSFX.PlayAudio();
}
}
IEnumerator I_ShakeTransform()
{
m_TransformIsShaking = true;
WaitForFixedUpdate wait = new WaitForFixedUpdate();
if (UseMuzzleFlash && MuzzleFlashObject)
{
MuzzleFlashObject.transform.localScale = Random.Range(.5f, 1.5f) * Vector3.one;
MuzzleFlashObject.SetActive(true);
}
float timer = 0;
startPos = transform.localPosition;
while (timer < ShakeDuration)
{
var pos = startPos + (Random.insideUnitSphere * ShakeAmount);
transform.localPosition = pos;
timer += Time.fixedDeltaTime;
yield return wait;
}
transform.localPosition = startPos;
if (UseMuzzleFlash && MuzzleFlashObject)
{
MuzzleFlashObject.SetActive(false);
}
m_TransformIsShaking = false;
}
}

Просмотреть файл

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 839028af332e14618a5c21629d48371c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -1,91 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class MultiGunAlternating : MonoBehaviour
{
[Header("INPUT")] public bool AllowKeyboardInput = true;
public KeyCode shootKey = KeyCode.J;
[Header("AUTOSHOOT")] public bool autoShootEnabled;
[Header("GUNS")] public List<GunController> gunList = new List<GunController>();
public int currentGunIndex;
[Header("TIMING")]
public float shootingRate = .02f; //can shoot every shootingRate seconds. ex: .5 can shoot every .5 seconds
private float shootTimer;
public bool coolDownComplete;
[Header("COOLDOWN & RELOAD")]
public float CurrentPercentage = 100; //the amount of ammo we currently have on a scale between 0-100
public float DepletionRate = 5f; //constant rate at which ammo depletes when being used
public float RegenRate = .25f; //constant rate at which ammo regenerates
public Slider UISlider;
// Start is called before the first frame update
void Start()
{
CurrentPercentage = 100;
if (UISlider)
{
UISlider.value = CurrentPercentage;
}
}
void ShootGunAtIndex(int i)
{
currentGunIndex = i >= gunList.Count - 1 ? 0 : i + 1;
gunList[currentGunIndex].Shoot();
shootTimer = 0;
}
public void Shoot()
{
coolDownComplete = shootTimer > shootingRate;
if (coolDownComplete)
{
ShootGunAtIndex(currentGunIndex);
CurrentPercentage = Mathf.Clamp(CurrentPercentage - DepletionRate, 0, 100);
}
}
void Update()
{
if (UISlider)
{
UISlider.value = CurrentPercentage;
}
}
void FixedUpdate()
{
// coolDownComplete = shootTimer > shootingRate;
// if (coolDownComplete)
// {
if (autoShootEnabled)
{
// ShootGunAtIndex(currentGunIndex);
Shoot();
}
if (AllowKeyboardInput && Input.GetKey(shootKey))
{
// ShootGunAtIndex(currentGunIndex);
Shoot();
}
// }
shootTimer += Time.fixedDeltaTime;
CurrentPercentage = Mathf.Clamp(CurrentPercentage + RegenRate, 0, 100);
}
// IEnumerator HandleShooting()
// {
// WaitForFixedUpdate wait = new WaitForFixedUpdate();
// }
}

Просмотреть файл

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 0759b2416b6374748b3c4bc904d0bdb7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: ab8d5017850634a23b597e0d658dd74c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -1,35 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(AudioSource))]
[RequireComponent(typeof(GunController))]
public class GunSFX : MonoBehaviour
{
public AudioClip BackgroundSong;
private AudioSource m_AudioSource;
public Vector2 SoundScaleRandomRange = new Vector2(.2f, .4f);
void Awake()
{
if (m_AudioSource == null)
{
m_AudioSource = GetComponent<AudioSource>();
// m_AudioSource = gameObject.AddComponent<AudioSource>();
}
}
// Update is called once per frame
void Update()
{
}
public void PlayAudio()
{
m_AudioSource.PlayOneShot(m_AudioSource.clip);
}
}

Просмотреть файл

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: ed5c9f45176ce4bbeb07979f182471e2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: