mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-30 04:57:10 +01:00
Grenades
[+] added + grenade.cs script + grenades can be thrown + grenades "explode" and spawn "explosion" (currently only a 50% transparent cube) - NEEDS TO BE TESTED => BUG FIXED
This commit is contained in:
@@ -5,12 +5,14 @@ using Mirror;
|
||||
using TMPro;
|
||||
public class Shoot : NetworkBehaviour
|
||||
{
|
||||
|
||||
[SerializeField] WeaponManager weaponManager; // For throwing grenade
|
||||
[SerializeField] GameObject muzzle;
|
||||
[SerializeField] ProcedualAnimationController shootAnim;
|
||||
[SerializeField] GameObject weaponHolder;
|
||||
[SerializeField] Camera mCamera;
|
||||
[SerializeField] bool limitAmmunition = true;
|
||||
|
||||
|
||||
private Weapon weapon;
|
||||
private RaycastHit crosshairHitPoint;
|
||||
private Vector3 _pointDirection;
|
||||
@@ -48,21 +50,37 @@ public class Shoot : NetworkBehaviour
|
||||
{
|
||||
weapon.GetComponent<BoxCollider>().enabled = false;
|
||||
}
|
||||
if (weapon.AllowAction && weapon.CurrentAmmunition > 0)
|
||||
{
|
||||
shootAnim.Recoil(0.1f);
|
||||
}
|
||||
CmdFireBullet();
|
||||
|
||||
// If current weapon kind is a rifle or pistole
|
||||
string weaponKindString = weapon.WeaponKind.ToString();
|
||||
if(weaponKindString == "Rifle" || weaponKindString == "Pistole") {
|
||||
if (weapon.AllowAction && weapon.CurrentAmmunition > 0) {
|
||||
shootAnim.Recoil(0.1f);
|
||||
}
|
||||
// Shoot Weapon
|
||||
CmdFireBullet();
|
||||
} // If current weapon kind is grenade
|
||||
else if(weaponKindString == "Grenade"){
|
||||
// Throw Grenade
|
||||
throwGrenade();
|
||||
} // If current weapon kind is kinfe
|
||||
else {
|
||||
// Throw hands (punch)
|
||||
}
|
||||
}
|
||||
if (Input.GetButtonDown("Reload")) {
|
||||
updateCanvas = true;
|
||||
CmdReloadWeapon();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void throwGrenade() {
|
||||
Debug.Log("ThrowGrenade!");
|
||||
// Throws grenade with dropForce
|
||||
weapon.HasBeenThrown = true;
|
||||
weaponManager.dropWeapon(weapon.DropForce);
|
||||
}
|
||||
|
||||
[Command]
|
||||
private void CmdReloadWeapon() {
|
||||
if (weapon.AllowAction && limitAmmunition) {
|
||||
|
||||
Reference in New Issue
Block a user