mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-29 12:52:07 +01:00
DebugCanvas and ShootDebug
Fixed DebugAmmunitionText on DebugCanvas Added hitForce on Weapons. When you hit an object with a rigidbody its going to fly back a little bit
This commit is contained in:
@@ -9,11 +9,14 @@ public class DebugCanvas : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI DebugTextGrounded;
|
||||
public TextMeshProUGUI DebugTextClientServer;
|
||||
public TextMeshProUGUI DebugAmmunition;
|
||||
public GameObject Player;
|
||||
public GameObject GameManager;
|
||||
public TextMeshProUGUI fpsText;
|
||||
public float deltaTime;
|
||||
|
||||
private Shoot shoot;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
GameManager = GameObject.Find("GameManager");
|
||||
@@ -26,6 +29,7 @@ public class DebugCanvas : MonoBehaviour
|
||||
try
|
||||
{
|
||||
Player = GameObject.FindGameObjectWithTag("Player").gameObject;
|
||||
shoot = Player.GetComponent<Shoot>();
|
||||
Debug.Log("Player Found");
|
||||
}
|
||||
catch
|
||||
@@ -37,6 +41,10 @@ public class DebugCanvas : MonoBehaviour
|
||||
else
|
||||
{
|
||||
DebugTextGrounded.text = "isGrounded: " + Player.GetComponent<PlayerController>().isGrounded.ToString();
|
||||
if (Player)
|
||||
{
|
||||
DebugAmmunition.text = shoot.CurAmmo + " / " + shoot.TotalAmmo;
|
||||
}
|
||||
deltaTime += (Time.deltaTime - deltaTime) * 0.1f;
|
||||
float fps = 1.0f / deltaTime;
|
||||
fpsText.text = Mathf.Ceil(fps).ToString() + "FPS";
|
||||
|
||||
@@ -12,7 +12,10 @@ public class Shoot : NetworkBehaviour
|
||||
[SerializeField] GameObject weaponHolder;
|
||||
[SerializeField] Camera mCamera;
|
||||
[SerializeField] bool limitAmmunition = true;
|
||||
|
||||
[Header("Debug")]
|
||||
[SerializeField] bool showBullethole = true;
|
||||
[SerializeField] float bulletholeRadius = 0.2f;
|
||||
|
||||
private Weapon weapon;
|
||||
private RaycastHit crosshairHitPoint;
|
||||
private Vector3 _pointDirection;
|
||||
@@ -23,8 +26,8 @@ public class Shoot : NetworkBehaviour
|
||||
private bool updateCanvas = true;
|
||||
private int curAmmo = 1, totalAmmo = 1;
|
||||
|
||||
public int CurAmmo { get => curAmmo; set => curAmmo = value; }
|
||||
public int TotalAmmo { get => totalAmmo; set => totalAmmo = value; }
|
||||
public int CurAmmo { get => curAmmo; set => curAmmo = value; } // For DebugCanvas
|
||||
public int TotalAmmo { get => totalAmmo; set => totalAmmo = value; } // For DebugCanvas
|
||||
|
||||
private void Start() {
|
||||
if (isServer) {
|
||||
@@ -100,7 +103,11 @@ public class Shoot : NetworkBehaviour
|
||||
|
||||
if (weapon.AllowAction) { // If not reloading etc.
|
||||
if (Physics.Raycast(muzzle.transform.position, muzzle.transform.forward, out hit) && weapon.CurrentAmmunition > 0) { // Raycast from Bullet Exit Point to camera raycast
|
||||
bulletHole(GameObject.CreatePrimitive(PrimitiveType.Sphere), hit); // Creates bullethole where raycast hits
|
||||
if (showBullethole) { bulletHole(GameObject.CreatePrimitive(PrimitiveType.Sphere), hit); } // Creates bullethole where raycast hits
|
||||
if (hit.transform.gameObject.GetComponent<Rigidbody>())
|
||||
{
|
||||
hit.transform.gameObject.GetComponent<Rigidbody>().AddForce(mCamera.transform.forward * weapon.HitForce);
|
||||
}
|
||||
if (hit.transform.gameObject.GetComponent<Player>() != null) { // If hit object is a player
|
||||
Debug.Log("-->HIT PLAYER: " + hit.transform.name);
|
||||
hit.transform.gameObject.GetComponent<Player>().RemoveHealth(weapon.Damage);
|
||||
@@ -115,7 +122,7 @@ public class Shoot : NetworkBehaviour
|
||||
|
||||
void bulletHole(GameObject holeObject, RaycastHit hit) // Nur zum testen da
|
||||
{
|
||||
holeObject.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f);
|
||||
holeObject.transform.localScale = new Vector3(bulletholeRadius, bulletholeRadius, bulletholeRadius);
|
||||
holeObject.transform.position = hit.point;
|
||||
}
|
||||
|
||||
@@ -129,6 +136,7 @@ public class Shoot : NetworkBehaviour
|
||||
private bool subtractAmmunition(Weapon weapon) { // Subtracts Ammunition from weapon
|
||||
if (weapon.CurrentAmmunition > 0) {
|
||||
weapon.CurrentAmmunition -= 1;
|
||||
Debug.Log(weapon.CurrentAmmunition + " / " + weapon.TotalAmmunition);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -11,6 +11,7 @@ public class Weapon : MonoBehaviour
|
||||
[Header("Weapon Info")]
|
||||
[SerializeField] weaponKinds weaponKind;
|
||||
[SerializeField] float dropForce = 10f;
|
||||
[SerializeField] float hitForce = 100f;
|
||||
[SerializeField] int damage = 0;
|
||||
[SerializeField] float firerate = 0;
|
||||
[SerializeField] float recoilStrength = 0;
|
||||
@@ -23,6 +24,7 @@ public class Weapon : MonoBehaviour
|
||||
[SerializeField] Animator weaponAnimator;
|
||||
[SerializeField] Transform gunRightREF;
|
||||
[SerializeField] Transform gunLeftREF;
|
||||
|
||||
//[Header("Grenade")]
|
||||
private bool hasBeenThrown = false;
|
||||
|
||||
@@ -40,6 +42,7 @@ public class Weapon : MonoBehaviour
|
||||
public Transform GunLeftREF { get => gunLeftREF; }
|
||||
public Transform GunRightREF { get => gunRightREF; }
|
||||
public bool HasBeenThrown { get => hasBeenThrown; set => hasBeenThrown = value; }
|
||||
public float HitForce { get => hitForce; set => hitForce = value; }
|
||||
|
||||
private void Start() {
|
||||
CurrentAmmunition = MagazinSize;
|
||||
|
||||
Reference in New Issue
Block a user