add: damage to lava
update: moved player gravitation to FixedUpdate update: GameController initialization is moved to Awake
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class DamagingObject : MonoBehaviour
|
||||
{
|
||||
public float hitRate = 1f;
|
||||
public float damage = 5f;
|
||||
|
||||
[SerializeField] float currentDelay = 0;
|
||||
|
||||
void Start() {
|
||||
if (hitRate != 0) currentDelay = 1 / hitRate;
|
||||
}
|
||||
|
||||
void Update() {
|
||||
if (hitRate != 0) currentDelay = Mathf.Clamp(currentDelay += Time.deltaTime, 0, 1 / hitRate);
|
||||
}
|
||||
|
||||
public void ReverseOnControllerColliderHit(ControllerColliderHit hit) {
|
||||
if (hit.controller.CompareTag("Player") && currentDelay == 1 / hitRate) {
|
||||
Player player = hit.controller.GetComponent<Player>();
|
||||
player.DealDamage(damage);
|
||||
currentDelay = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fb7839678d2d2f7429a6dbd22c7efb93
|
||||
@@ -13,7 +13,7 @@ public class GameController : MonoBehaviour
|
||||
public List<EnemyInfo> enemies;
|
||||
public Dictionary<BulletType, int> inventory = new();
|
||||
|
||||
public void Start() {
|
||||
public void Awake() {
|
||||
if (i) { Destroy(gameObject); return; }
|
||||
i = GetComponent<GameController>();
|
||||
DontDestroyOnLoad(gameObject);
|
||||
|
||||
@@ -31,10 +31,13 @@ public class PlayerMovement : MonoBehaviour
|
||||
HandleJumping();
|
||||
HandleMovement();
|
||||
HandleDashing();
|
||||
DoGravity();
|
||||
HandleConstantVelocity();
|
||||
}
|
||||
|
||||
void FixedUpdate() {
|
||||
DoGravity();
|
||||
}
|
||||
|
||||
void HandleJumping() {
|
||||
if (movementInactive > 0) return;
|
||||
if (Input.GetKey(KeyCode.Space) && grounded) {
|
||||
@@ -70,12 +73,12 @@ public class PlayerMovement : MonoBehaviour
|
||||
void DoGravity() {
|
||||
if (gravityInactive > 0) {
|
||||
gravityVelocity = Vector3.zero;
|
||||
gravityInactive = Mathf.Max(gravityInactive -= Time.deltaTime, 0);
|
||||
gravityInactive = Mathf.Max(gravityInactive -= Time.fixedDeltaTime, 0);
|
||||
return;
|
||||
}
|
||||
if (grounded && gravityVelocity.y < 0) gravityVelocity = Vector3.zero;
|
||||
gravityVelocity += Physics.gravity * (Time.deltaTime * gravityMultiplier);
|
||||
characterController.Move(gravityVelocity * Time.deltaTime);
|
||||
gravityVelocity += Physics.gravity * (Time.fixedDeltaTime * gravityMultiplier);
|
||||
characterController.Move(gravityVelocity * Time.fixedDeltaTime);
|
||||
}
|
||||
|
||||
void HandleConstantVelocity() {
|
||||
|
||||
Reference in New Issue
Block a user