using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WeaponManager : MonoBehaviour
{
public static WeaponManager Instance { get; set; }
public List<GameObject> weaponSlots;
public GameObject activeWeaponSlot;
[Header("Ammo")]
public int totalARAmmo = 0;
public int totalPistolAmmo = 0;
[Header("Throwables General")]
public float throwForce = 10f;
public GameObject throwableSpawn;
public float forceMultiplier = 0;
public float forceMultiplierLimit = 2;
[Header("Lethals")]
public int lethalsCount = 0;
public Throwable.ThrowableType equippedLethalType;
public GameObject fragPrefab;
private void Awake()
{
if (Instance != null && Instance != this)
{
Destroy(gameObject);
}
else
{
Instance = this;
}
}
private void Start()
{
activeWeaponSlot = weaponSlots[0];
}
private void Update()
{
foreach (GameObject weaponSlot in weaponSlots)
{
if (weaponSlot == activeWeaponSlot)
{
weaponSlot.SetActive(true);
}
else
{
weaponSlot.SetActive(false);
}
}
if (Input.GetKeyDown(KeyCode.Alpha1))
{
SwitchActiveSlot(0);
}
if (Input.GetKeyDown(KeyCode.Alpha2))
{
SwitchActiveSlot(1);
}
if (Input.GetKey(KeyCode.G))
{
forceMultiplier += Time.deltaTime;
if (forceMultiplier > forceMultiplierLimit)
{
forceMultiplier = forceMultiplierLimit;
}
}
if (Input.GetKeyUp(KeyCode.G))
{
if (lethalsCount > 0)
{
ThrowLethal();
}
forceMultiplier = 0;
}
}
public void PickupWeapon(GameObject pickedupWeapon)
{
AddWeaponIntoActiveSlot(pickedupWeapon);
}
private void AddWeaponIntoActiveSlot(GameObject pickedupWeapon)
{
DropCurrentWeapon(pickedupWeapon);
pickedupWeapon.transform.SetParent(activeWeaponSlot.transform, false);
Weapon weapon = pickedupWeapon.GetComponent<Weapon>();
pickedupWeapon.transform.localPosition = new Vector3(weapon.spawnPosition.x, weapon.spawnPosition.y, weapon.spawnPosition.z);
pickedupWeapon.transform.localRotation = Quaternion.Euler(weapon.spawnRotation.x, weapon.spawnRotation.y, weapon.spawnRotation.z);
weapon.isActiveWeapon = true;
weapon.animator.enabled = true;
}
internal void PickupAmmo(AmmoBox ammo)
{
switch (ammo.ammoType)
{
case AmmoBox.AmmoType.Pistol_Ammo:
totalPistolAmmo += ammo.ammoAmount;
break;
case AmmoBox.AmmoType.AssaultRifle_Ammo:
totalARAmmo += ammo.ammoAmount;
break;
}
}
private void DropCurrentWeapon(GameObject pickedupWeapon)
{
if (activeWeaponSlot.transform.childCount > 0)
{
var weaponToDrop = activeWeaponSlot.transform.GetChild(0).gameObject;
weaponToDrop.GetComponent<Weapon>().isActiveWeapon = false;
weaponToDrop.GetComponent<Weapon>().animator.enabled = false;
weaponToDrop.transform.SetParent(pickedupWeapon.transform.parent);
weaponToDrop.transform.localPosition = pickedupWeapon.transform.localPosition;
weaponToDrop.transform.localRotation = pickedupWeapon.transform.localRotation;
}
}
public void SwitchActiveSlot(int slotNumber)
{
if (activeWeaponSlot.transform.childCount > 0)
{
Weapon currentWeapon = activeWeaponSlot.transform.GetChild(0).GetComponent<Weapon>();
currentWeapon.isActiveWeapon = false;
}
activeWeaponSlot = weaponSlots[slotNumber];
if (activeWeaponSlot.transform.childCount > 0)
{
Weapon newWeapon = activeWeaponSlot.transform.GetChild(0).GetComponent<Weapon>();
newWeapon.isActiveWeapon = true;
}
}
//Weapon sprite
internal void DecreaseTotalAmmo(int bulletsToDecrease, Weapon.WeaponModel thisWeaponModel)
{
switch (thisWeaponModel)
{
case Weapon.WeaponModel.SVA_545:
totalARAmmo -= bulletsToDecrease;
break;
case Weapon.WeaponModel.FF_Magnum:
totalPistolAmmo -= bulletsToDecrease;
break;
case Weapon.WeaponModel.Glock:
totalPistolAmmo -= bulletsToDecrease;
break;
}
}
//Ammo sprite
public int CheckAmmoLeftFor(Weapon.WeaponModel thisWeaponModel)
{
switch (thisWeaponModel)
{
case Weapon.WeaponModel.SVA_545:
return totalARAmmo;
case Weapon.WeaponModel.FF_Magnum:
return totalPistolAmmo;
case Weapon.WeaponModel.Glock:
return totalPistolAmmo;
default:
return 0;
}
}
#region || ---- Throwables ---- ||
public void PickupThrowable(Throwable throwable)
{
switch (throwable.throwableType)
{
case Throwable.ThrowableType.Frag:
PickupThrowableAsLethal(Throwable.ThrowableType.Frag);
break;
}
}
private void PickupThrowableAsLethal(Throwable.ThrowableType lethal)
{
if (equippedLethalType == lethal || equippedLethalType == Throwable.ThrowableType.None)
{
equippedLethalType = lethal;
if (lethalsCount < 3)
{
lethalsCount += 1;
Destroy(InteractionManager.Instance.hoveredThrowable.gameObject);
HUDmanager.Instance.UpdateThrowables();
}
else{
print("Lethals limit reached.");
}
}
else
{
//Cannot pick up differnt lethal
//Option to swap lethal
}
}
private void ThrowLethal()
{
GameObject lethalPrefab = GetThrowablePrefab();
GameObject throwable = Instantiate(lethalPrefab, throwableSpawn.transform.position, Camera.main.transform.rotation);
Rigidbody rb = throwable.GetComponent<Rigidbody>();
rb.AddForce(Camera.main.transform.forward * (throwForce * forceMultiplier), ForceMode.Impulse);
throwable.GetComponent<Throwable>().hasBeenThrown = true;
lethalsCount -= 1;
if (lethalsCount <= 0)
{
equippedLethalType = Throwable.ThrowableType.None;
}
HUDmanager.Instance.UpdateThrowables();
}
private GameObject GetThrowablePrefab()
{
switch (equippedLethalType)
{
case Throwable.ThrowableType.Frag:
return fragPrefab;
}
return new();
}
#endregion
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Throwable : MonoBehaviour
{
[SerializeField] float delay = 3f;
[SerializeField] float damageRadius = 20f;
[SerializeField] float explosionForce = 1200f;
float countdown;
bool hasExploded = false;
public bool hasBeenThrown = false;
public enum ThrowableType
{
None,
Frag
}
public ThrowableType throwableType;
private void Start()
{
countdown = delay;
equippedLethalType = Throwable.ThrowableType.None;
}
private void Update()
{
if (hasBeenThrown)
{
countdown -= Time.deltaTime;
if (countdown <= 0f && !hasExploded)
{
Explode();
hasExploded = true;
}
}
}
private void Explode()
{
GetThrowableEffect();
Destroy(gameObject);
}
private void GetThrowableEffect()
{
switch (throwableType)
{
case ThrowableType.Frag:
FragEffect();
break;
}
}
private void FragEffect()
{
//Visuals
GameObject explosionEffect = GlobalReferences.Instance.fragExplosionEffect;
Instantiate(explosionEffect, transform.position, transform.rotation);
//Play sound
SoundManager.Instance.throwablesChannel.PlayOneShot(SoundManager.Instance.fragSound);
//Physicals
Collider[] colliders = Physics.OverlapSphere(transform.position, damageRadius);
foreach (Collider objectInRange in colliders)
{
Rigidbody rb = objectInRange.GetComponent<Rigidbody>();
if (rb != null)
{
rb.AddExplosionForce(explosionForce, transform.position, damageRadius);
}
//Also apply damage to enemy over here
}
}
}
My error is…
Assets\Scripts\Throwable.cs(28,9): error CS0103: The name ‘equippedLethalType’ does not exist in the current context
Not sure why its like this. If someone could help me understand more what this error is that would be very helpful !!!