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:
@@ -591,6 +591,8 @@ MonoBehaviour:
|
|||||||
weaponHolder: {fileID: 5071598280516985511, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
|
weaponHolder: {fileID: 5071598280516985511, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
|
||||||
mCamera: {fileID: 6272346181657429395}
|
mCamera: {fileID: 6272346181657429395}
|
||||||
limitAmmunition: 1
|
limitAmmunition: 1
|
||||||
|
showBullethole: 1
|
||||||
|
bulletholeRadius: 0.1
|
||||||
--- !u!114 &320375778840406984
|
--- !u!114 &320375778840406984
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
@@ -656,15 +656,15 @@ PrefabInstance:
|
|||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 732033708985862910, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
|
- target: {fileID: 732033708985862910, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
|
||||||
propertyPath: m_LocalPosition.x
|
propertyPath: m_LocalPosition.x
|
||||||
value: 5.871
|
value: 4.213
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 732033708985862910, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
|
- target: {fileID: 732033708985862910, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
|
||||||
propertyPath: m_LocalPosition.y
|
propertyPath: m_LocalPosition.y
|
||||||
value: 1.885
|
value: 0.835
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 732033708985862910, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
|
- target: {fileID: 732033708985862910, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
|
||||||
propertyPath: m_LocalPosition.z
|
propertyPath: m_LocalPosition.z
|
||||||
value: -5.008
|
value: 2.009
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 732033708985862910, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
|
- target: {fileID: 732033708985862910, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
|
||||||
propertyPath: m_LocalRotation.w
|
propertyPath: m_LocalRotation.w
|
||||||
@@ -1555,6 +1555,10 @@ PrefabInstance:
|
|||||||
propertyPath: m_Materials.Array.data[0]
|
propertyPath: m_Materials.Array.data[0]
|
||||||
value:
|
value:
|
||||||
objectReference: {fileID: 2100000, guid: 7e832beb11d0b11499c8a1b3b4e52e78, type: 2}
|
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}
|
- target: {fileID: 1672832146417829139, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
|
||||||
propertyPath: gunLeftREF
|
propertyPath: gunLeftREF
|
||||||
value:
|
value:
|
||||||
@@ -1589,7 +1593,7 @@ PrefabInstance:
|
|||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 8797726366404580855, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
|
- target: {fileID: 8797726366404580855, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
|
||||||
propertyPath: m_LocalPosition.x
|
propertyPath: m_LocalPosition.x
|
||||||
value: 0
|
value: 4.47
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 8797726366404580855, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
|
- target: {fileID: 8797726366404580855, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
|
||||||
propertyPath: m_LocalPosition.y
|
propertyPath: m_LocalPosition.y
|
||||||
@@ -3496,6 +3500,7 @@ MonoBehaviour:
|
|||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
DebugTextGrounded: {fileID: 987854205}
|
DebugTextGrounded: {fileID: 987854205}
|
||||||
DebugTextClientServer: {fileID: 0}
|
DebugTextClientServer: {fileID: 0}
|
||||||
|
DebugAmmunition: {fileID: 1430445133}
|
||||||
Player: {fileID: 6272346181302961293, guid: a14d876ac00bdf6498e30b3e58b68fdf, type: 3}
|
Player: {fileID: 6272346181302961293, guid: a14d876ac00bdf6498e30b3e58b68fdf, type: 3}
|
||||||
GameManager: {fileID: 0}
|
GameManager: {fileID: 0}
|
||||||
fpsText: {fileID: 72243808}
|
fpsText: {fileID: 72243808}
|
||||||
|
|||||||
@@ -9,11 +9,14 @@ public class DebugCanvas : MonoBehaviour
|
|||||||
{
|
{
|
||||||
public TextMeshProUGUI DebugTextGrounded;
|
public TextMeshProUGUI DebugTextGrounded;
|
||||||
public TextMeshProUGUI DebugTextClientServer;
|
public TextMeshProUGUI DebugTextClientServer;
|
||||||
|
public TextMeshProUGUI DebugAmmunition;
|
||||||
public GameObject Player;
|
public GameObject Player;
|
||||||
public GameObject GameManager;
|
public GameObject GameManager;
|
||||||
public TextMeshProUGUI fpsText;
|
public TextMeshProUGUI fpsText;
|
||||||
public float deltaTime;
|
public float deltaTime;
|
||||||
|
|
||||||
|
private Shoot shoot;
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
GameManager = GameObject.Find("GameManager");
|
GameManager = GameObject.Find("GameManager");
|
||||||
@@ -26,6 +29,7 @@ public class DebugCanvas : MonoBehaviour
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Player = GameObject.FindGameObjectWithTag("Player").gameObject;
|
Player = GameObject.FindGameObjectWithTag("Player").gameObject;
|
||||||
|
shoot = Player.GetComponent<Shoot>();
|
||||||
Debug.Log("Player Found");
|
Debug.Log("Player Found");
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
@@ -37,6 +41,10 @@ public class DebugCanvas : MonoBehaviour
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
DebugTextGrounded.text = "isGrounded: " + Player.GetComponent<PlayerController>().isGrounded.ToString();
|
DebugTextGrounded.text = "isGrounded: " + Player.GetComponent<PlayerController>().isGrounded.ToString();
|
||||||
|
if (Player)
|
||||||
|
{
|
||||||
|
DebugAmmunition.text = shoot.CurAmmo + " / " + shoot.TotalAmmo;
|
||||||
|
}
|
||||||
deltaTime += (Time.deltaTime - deltaTime) * 0.1f;
|
deltaTime += (Time.deltaTime - deltaTime) * 0.1f;
|
||||||
float fps = 1.0f / deltaTime;
|
float fps = 1.0f / deltaTime;
|
||||||
fpsText.text = Mathf.Ceil(fps).ToString() + "FPS";
|
fpsText.text = Mathf.Ceil(fps).ToString() + "FPS";
|
||||||
|
|||||||
@@ -12,7 +12,10 @@ public class Shoot : NetworkBehaviour
|
|||||||
[SerializeField] GameObject weaponHolder;
|
[SerializeField] GameObject weaponHolder;
|
||||||
[SerializeField] Camera mCamera;
|
[SerializeField] Camera mCamera;
|
||||||
[SerializeField] bool limitAmmunition = true;
|
[SerializeField] bool limitAmmunition = true;
|
||||||
|
[Header("Debug")]
|
||||||
|
[SerializeField] bool showBullethole = true;
|
||||||
|
[SerializeField] float bulletholeRadius = 0.2f;
|
||||||
|
|
||||||
private Weapon weapon;
|
private Weapon weapon;
|
||||||
private RaycastHit crosshairHitPoint;
|
private RaycastHit crosshairHitPoint;
|
||||||
private Vector3 _pointDirection;
|
private Vector3 _pointDirection;
|
||||||
@@ -23,8 +26,8 @@ public class Shoot : NetworkBehaviour
|
|||||||
private bool updateCanvas = true;
|
private bool updateCanvas = true;
|
||||||
private int curAmmo = 1, totalAmmo = 1;
|
private int curAmmo = 1, totalAmmo = 1;
|
||||||
|
|
||||||
public int CurAmmo { get => curAmmo; set => curAmmo = value; }
|
public int CurAmmo { get => curAmmo; set => curAmmo = value; } // For DebugCanvas
|
||||||
public int TotalAmmo { get => totalAmmo; set => totalAmmo = value; }
|
public int TotalAmmo { get => totalAmmo; set => totalAmmo = value; } // For DebugCanvas
|
||||||
|
|
||||||
private void Start() {
|
private void Start() {
|
||||||
if (isServer) {
|
if (isServer) {
|
||||||
@@ -100,7 +103,11 @@ public class Shoot : NetworkBehaviour
|
|||||||
|
|
||||||
if (weapon.AllowAction) { // If not reloading etc.
|
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
|
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
|
if (hit.transform.gameObject.GetComponent<Player>() != null) { // If hit object is a player
|
||||||
Debug.Log("-->HIT PLAYER: " + hit.transform.name);
|
Debug.Log("-->HIT PLAYER: " + hit.transform.name);
|
||||||
hit.transform.gameObject.GetComponent<Player>().RemoveHealth(weapon.Damage);
|
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
|
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;
|
holeObject.transform.position = hit.point;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,6 +136,7 @@ public class Shoot : NetworkBehaviour
|
|||||||
private bool subtractAmmunition(Weapon weapon) { // Subtracts Ammunition from weapon
|
private bool subtractAmmunition(Weapon weapon) { // Subtracts Ammunition from weapon
|
||||||
if (weapon.CurrentAmmunition > 0) {
|
if (weapon.CurrentAmmunition > 0) {
|
||||||
weapon.CurrentAmmunition -= 1;
|
weapon.CurrentAmmunition -= 1;
|
||||||
|
Debug.Log(weapon.CurrentAmmunition + " / " + weapon.TotalAmmunition);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ public class Weapon : MonoBehaviour
|
|||||||
[Header("Weapon Info")]
|
[Header("Weapon Info")]
|
||||||
[SerializeField] weaponKinds weaponKind;
|
[SerializeField] weaponKinds weaponKind;
|
||||||
[SerializeField] float dropForce = 10f;
|
[SerializeField] float dropForce = 10f;
|
||||||
|
[SerializeField] float hitForce = 100f;
|
||||||
[SerializeField] int damage = 0;
|
[SerializeField] int damage = 0;
|
||||||
[SerializeField] float firerate = 0;
|
[SerializeField] float firerate = 0;
|
||||||
[SerializeField] float recoilStrength = 0;
|
[SerializeField] float recoilStrength = 0;
|
||||||
@@ -23,6 +24,7 @@ public class Weapon : MonoBehaviour
|
|||||||
[SerializeField] Animator weaponAnimator;
|
[SerializeField] Animator weaponAnimator;
|
||||||
[SerializeField] Transform gunRightREF;
|
[SerializeField] Transform gunRightREF;
|
||||||
[SerializeField] Transform gunLeftREF;
|
[SerializeField] Transform gunLeftREF;
|
||||||
|
|
||||||
//[Header("Grenade")]
|
//[Header("Grenade")]
|
||||||
private bool hasBeenThrown = false;
|
private bool hasBeenThrown = false;
|
||||||
|
|
||||||
@@ -40,6 +42,7 @@ public class Weapon : MonoBehaviour
|
|||||||
public Transform GunLeftREF { get => gunLeftREF; }
|
public Transform GunLeftREF { get => gunLeftREF; }
|
||||||
public Transform GunRightREF { get => gunRightREF; }
|
public Transform GunRightREF { get => gunRightREF; }
|
||||||
public bool HasBeenThrown { get => hasBeenThrown; set => hasBeenThrown = value; }
|
public bool HasBeenThrown { get => hasBeenThrown; set => hasBeenThrown = value; }
|
||||||
|
public float HitForce { get => hitForce; set => hitForce = value; }
|
||||||
|
|
||||||
private void Start() {
|
private void Start() {
|
||||||
CurrentAmmunition = MagazinSize;
|
CurrentAmmunition = MagazinSize;
|
||||||
|
|||||||
Reference in New Issue
Block a user