Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# This .gitignore file should be placed at the root of your Unity project directory
#
# Get latest from https://github.com/github/gitignore/blob/main/Unity.gitignore
#
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/[Ll]ogs/
/[Uu]ser[Ss]ettings/
/[Pp]ackages/

# MemoryCaptures can get excessive in size.
# They also could contain extremely sensitive data
/[Mm]emoryCaptures/

# Recordings can get excessive in size
/[Rr]ecordings/

# Uncomment this line if you wish to ignore the asset store tools plugin
# /[Aa]ssets/AssetStoreTools*

# Autogenerated Jetbrains Rider plugin
/[Aa]ssets/Plugins/Editor/JetBrains*

# Visual Studio cache directory
.vs/

# Gradle cache directory
.gradle/

# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
*.pdb
*.mdb
*.opendb
*.VC.db

# Unity3D generated meta files
*.pidb.meta
*.pdb.meta
*.mdb.meta

# Unity3D generated file on crash reports
sysinfo.txt

# Builds
*.apk
*.aab
*.unitypackage
*.unitypackage.meta
*.app

# Crashlytics generated file
crashlytics-build.properties

# Packed Addressables
/[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin*

# Temporary auto-generated Android Assets
/[Aa]ssets/[Ss]treamingAssets/aa.meta
/[Aa]ssets/[Ss]treamingAssets/aa/*
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"visualstudiotoolsforunity.vstuc"
]
}
10 changes: 10 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to Unity",
"type": "vstuc",
"request": "attach"
}
]
}
70 changes: 70 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"files.exclude": {
"**/.DS_Store": true,
"**/.git": true,
"**/.vs": true,
"**/.gitmodules": true,
"**/.vsconfig": true,
"**/*.booproj": true,
"**/*.pidb": true,
"**/*.suo": true,
"**/*.user": true,
"**/*.userprefs": true,
"**/*.unityproj": true,
"**/*.dll": true,
"**/*.exe": true,
"**/*.pdf": true,
"**/*.mid": true,
"**/*.midi": true,
"**/*.wav": true,
"**/*.gif": true,
"**/*.ico": true,
"**/*.jpg": true,
"**/*.jpeg": true,
"**/*.png": true,
"**/*.psd": true,
"**/*.tga": true,
"**/*.tif": true,
"**/*.tiff": true,
"**/*.3ds": true,
"**/*.3DS": true,
"**/*.fbx": true,
"**/*.FBX": true,
"**/*.lxo": true,
"**/*.LXO": true,
"**/*.ma": true,
"**/*.MA": true,
"**/*.obj": true,
"**/*.OBJ": true,
"**/*.asset": true,
"**/*.cubemap": true,
"**/*.flare": true,
"**/*.mat": true,
"**/*.meta": true,
"**/*.prefab": true,
"**/*.unity": true,
"build/": true,
"Build/": true,
"Library/": true,
"library/": true,
"obj/": true,
"Obj/": true,
"Logs/": true,
"logs/": true,
"ProjectSettings/": true,
"UserSettings/": true,
"temp/": true,
"Temp/": true
},
"files.associations": {
"*.asset": "yaml",
"*.meta": "yaml",
"*.prefab": "yaml",
"*.unity": "yaml",
},
"explorer.fileNesting.enabled": true,
"explorer.fileNesting.patterns": {
"*.sln": "*.csproj",
},
"dotnet.defaultSolution": "Modular Systems.sln"
}
8 changes: 8 additions & 0 deletions Assets/Basic Projectile Gun System.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions Assets/Basic Projectile Gun System/GunIScriptableObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

[CreateAssetMenu(menuName = "Gun Object", order = 0)]
public class GunIScriptableObject : Stats
{
public GameObject gun;

[Header("Properties")]
public float bulletSpeed;
public float range;
public int ammo;
public float reloadTime;

[Header("Objects")]
public AudioClip audioClip;

[Header("Activity")]
public bool active;
public bool infiniteAmmo = false;


}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

135 changes: 135 additions & 0 deletions Assets/Basic Projectile Gun System/GunManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using UnityEngine.InputSystem;

public class GunManager : MonoBehaviour
{
ObjectPooler pool;
InputSystem_Actions input;

public List<GunIScriptableObject> gunTypes;
GunIScriptableObject activeGun;

bool isReloading = false;
int currAmmo = 0;

float canFire, fireInput = 0;

[SerializeField] Vector3 reloadRotation;
[SerializeField] Transform gunParent;
AudioSource audioSource;

[Header("Objects")]
Transform shellSpawn;
List<ParticleSystem> muzzleFlash = new List<ParticleSystem>();
List<GameObject> flashLight = new List<GameObject>();
public List<Transform> muzzle = new List<Transform>();

private void Start()
{
pool = ObjectPooler.instance;
input = new InputSystem_Actions();
audioSource = GetComponent<AudioSource>();

//gunTypes[Random.Range(0, gunTypes.Count)].active = true; //To get a random gun type

foreach (GunIScriptableObject item in gunTypes)
{
if (item.active)
{
activeGun = item;
//item.active = false; //To save the last active gun
break;
}
}

if (activeGun == null) activeGun = gunTypes[Random.Range(0, gunTypes.Count)];

Transform gunInstance = Instantiate(activeGun.gun, gunParent).transform;
Debug.Log(gunInstance.name);

for (int i = 0; i < gunInstance.childCount; i++)
{
Transform item = gunInstance.transform.GetChild(i);

if (item.CompareTag("muzzle") && item != null)
{
muzzle.Add(item);
flashLight.Add(item.Find("Flash").gameObject);
muzzleFlash.Add(item.Find("Muzzle Flash").GetComponent<ParticleSystem>());
}

if (item.gameObject.name == "Mag") shellSpawn = item;
}

currAmmo = activeGun.ammo;
}

private void OnEnable()
{
input.Enable();
input.Player.Attack.performed += ctx => Attack();
}

void Attack()
{
if (isReloading) return;

if (currAmmo <= 0)
{
StartCoroutine(reloading());
return;
}

if (canFire <= Time.time)
{
if (activeGun.getStat(StatTypes.attackCooldown) > 0) canFire = Time.time + (1 / (activeGun.getStat(StatTypes.attackCooldown) / 60f));
else canFire = Time.time;

StartCoroutine(Shoot());
}
}

IEnumerator Shoot()
{
if (pool != null)
{
if (!activeGun.infiniteAmmo) currAmmo--;

for (int i = 0; i < muzzle.Count; i++)
{
if (muzzle[i].gameObject.activeInHierarchy)
{
GameObject bullet = pool.GetObject(1);
bullet.transform.SetPositionAndRotation(muzzle[i].position, muzzle[i].rotation);
bullet.GetComponent<Rigidbody>().AddForce(muzzle[i].forward * activeGun.bulletSpeed, ForceMode.Impulse);
muzzleFlash[i].Play();
flashLight[i].SetActive(true);
StartCoroutine(bullet.GetComponent<bullet>().Initialise(activeGun.range));
}
}

GameObject shell = pool.GetObject(3);
shell.transform.SetPositionAndRotation(shellSpawn.position, shellSpawn.rotation);

audioSource.PlayOneShot(activeGun.audioClip);

yield return new WaitForSeconds(.2f);

foreach (GameObject item in flashLight) item.SetActive(false);
}
}

IEnumerator reloading()
{
Debug.Log("Reloading");
isReloading = true;

yield return new WaitForSeconds(activeGun.reloadTime);
isReloading = false;

currAmmo = activeGun.ammo;
}
}
2 changes: 2 additions & 0 deletions Assets/Basic Projectile Gun System/GunManager.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions Assets/Basic Projectile Gun System/bullet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(Rigidbody))]
public class bullet : MonoBehaviour
{
public IEnumerator Initialise(float range)
{
yield return new WaitForSeconds(range);
gameObject.GetComponent<Rigidbody>().linearVelocity = Vector3.zero;
if (ObjectPooler.instance != null) ObjectPooler.instance.ReturnObject(gameObject, 1);
}
}
2 changes: 2 additions & 0 deletions Assets/Basic Projectile Gun System/bullet.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Defaults.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading