diff --git a/Assets/Prefabs/Player/Player.prefab b/Assets/Prefabs/Player/Player.prefab index e1b5378..aaf4247 100644 --- a/Assets/Prefabs/Player/Player.prefab +++ b/Assets/Prefabs/Player/Player.prefab @@ -591,6 +591,8 @@ MonoBehaviour: weaponHolder: {fileID: 5071598280516985511, guid: bd217f9f85ce78e46a925776562625e8, type: 3} mCamera: {fileID: 6272346181657429395} limitAmmunition: 1 + showBullethole: 1 + bulletholeRadius: 0.1 --- !u!114 &320375778840406984 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/TestScene.unity b/Assets/Scenes/TestScene.unity index a0a8f6d..179e31b 100644 --- a/Assets/Scenes/TestScene.unity +++ b/Assets/Scenes/TestScene.unity @@ -656,15 +656,15 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 732033708985862910, guid: bd217f9f85ce78e46a925776562625e8, type: 3} propertyPath: m_LocalPosition.x - value: 5.871 + value: 4.213 objectReference: {fileID: 0} - target: {fileID: 732033708985862910, guid: bd217f9f85ce78e46a925776562625e8, type: 3} propertyPath: m_LocalPosition.y - value: 1.885 + value: 0.835 objectReference: {fileID: 0} - target: {fileID: 732033708985862910, guid: bd217f9f85ce78e46a925776562625e8, type: 3} propertyPath: m_LocalPosition.z - value: -5.008 + value: 2.009 objectReference: {fileID: 0} - target: {fileID: 732033708985862910, guid: bd217f9f85ce78e46a925776562625e8, type: 3} propertyPath: m_LocalRotation.w @@ -1555,6 +1555,10 @@ PrefabInstance: propertyPath: m_Materials.Array.data[0] value: objectReference: {fileID: 2100000, guid: 7e832beb11d0b11499c8a1b3b4e52e78, type: 2} + - target: {fileID: 1672832146417829139, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3} + propertyPath: hitForce + value: 200 + objectReference: {fileID: 0} - target: {fileID: 1672832146417829139, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3} propertyPath: gunLeftREF value: @@ -1589,7 +1593,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 8797726366404580855, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3} propertyPath: m_LocalPosition.x - value: 0 + value: 4.47 objectReference: {fileID: 0} - target: {fileID: 8797726366404580855, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3} propertyPath: m_LocalPosition.y @@ -3496,6 +3500,7 @@ MonoBehaviour: m_EditorClassIdentifier: DebugTextGrounded: {fileID: 987854205} DebugTextClientServer: {fileID: 0} + DebugAmmunition: {fileID: 1430445133} Player: {fileID: 6272346181302961293, guid: a14d876ac00bdf6498e30b3e58b68fdf, type: 3} GameManager: {fileID: 0} fpsText: {fileID: 72243808} diff --git a/Assets/Scripts/DebugCanvas.cs b/Assets/Scripts/DebugCanvas.cs index 019553a..15b63a5 100644 --- a/Assets/Scripts/DebugCanvas.cs +++ b/Assets/Scripts/DebugCanvas.cs @@ -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(); Debug.Log("Player Found"); } catch @@ -37,6 +41,10 @@ public class DebugCanvas : MonoBehaviour else { DebugTextGrounded.text = "isGrounded: " + Player.GetComponent().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"; diff --git a/Assets/Scripts/Weapons/Shoot.cs b/Assets/Scripts/Weapons/Shoot.cs index c9be8e2..680ce0c 100644 --- a/Assets/Scripts/Weapons/Shoot.cs +++ b/Assets/Scripts/Weapons/Shoot.cs @@ -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()) + { + hit.transform.gameObject.GetComponent().AddForce(mCamera.transform.forward * weapon.HitForce); + } if (hit.transform.gameObject.GetComponent() != null) { // If hit object is a player Debug.Log("-->HIT PLAYER: " + hit.transform.name); hit.transform.gameObject.GetComponent().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; diff --git a/Assets/Scripts/Weapons/Weapon.cs b/Assets/Scripts/Weapons/Weapon.cs index c629323..070d752 100644 --- a/Assets/Scripts/Weapons/Weapon.cs +++ b/Assets/Scripts/Weapons/Weapon.cs @@ -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;