add: player UI

update: some enemies balance
This commit is contained in:
KOSMOGOR
2025-04-28 14:20:49 +03:00
parent a8cce441c3
commit d4589318f2
9 changed files with 550 additions and 17 deletions
+2
View File
@@ -16,4 +16,6 @@ public class Player : MonoBehaviour
FindAnyObjectByType<LevelController>().OnPlayerDie();
}
}
public float GetHp() { return hp; }
}
+27
View File
@@ -0,0 +1,27 @@
using System;
using TMPro;
using UnityEngine;
public class PlayerInterface : MonoBehaviour
{
public TMP_Text textTime;
public TMP_Text textHP;
public TMP_Text textBullets;
Player player;
WeaponController weaponController;
LevelController levelController;
void Start() {
player = GetComponentInParent<Player>();
weaponController = GetComponentInParent<WeaponController>();
levelController = FindFirstObjectByType<LevelController>();
}
void Update() {
if (levelController) textTime.text = TimeSpan.FromSeconds(levelController.GetTimeSpent()).ToString(@"mm\:ss");
textHP.text = $"{(int)player.GetHp()}/{player.maxHp}";
Weapon currentWeapon = weaponController.GetCurrentWeapon();
textBullets.text = currentWeapon && currentWeapon.bulletType != BulletType.None ? GameController.i.GetBulletCount(currentWeapon.bulletType).ToString() : "-";
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 1034c9030ffcd9b48b11a0c83921cc28
+3 -3
View File
@@ -47,7 +47,7 @@ public class PlayerMovement : MonoBehaviour
void HandleJumping() {
if (Input.GetKey(KeyCode.Space) && grounded) {
gravityVelocity = Vector3.up * (jumpForce * gravityMultiplier);
gravityVelocity = Vector3.up * jumpForce;
}
}
@@ -64,8 +64,8 @@ public class PlayerMovement : MonoBehaviour
void DoGravity() {
if (grounded && gravityVelocity.y < 0) gravityVelocity = Vector3.zero;
gravityVelocity += Physics.gravity * Time.deltaTime;
characterController.Move(gravityVelocity * (Time.deltaTime * gravityMultiplier));
gravityVelocity += Physics.gravity * (Time.deltaTime * gravityMultiplier);
characterController.Move(gravityVelocity * Time.deltaTime);
}
void OnControllerColliderHit(ControllerColliderHit hit) {
@@ -32,4 +32,6 @@ public class WeaponController : MonoBehaviour
weapons[ind].SetWeaponState(true);
currentWeapon = ind;
}
public Weapon GetCurrentWeapon() { return weapons.Length > 0 ? weapons[currentWeapon] : null; }
}