Edited with Error
코드 리뷰 후 에러가 있는 코드
This commit is contained in:
parent
42fb98cf8a
commit
79d947d176
|
|
@ -3,13 +3,9 @@ using UnityEngine.Events;
|
|||
|
||||
public class Entity : MonoBehaviour
|
||||
{
|
||||
public float maxHealth { get; private set; }
|
||||
public float currentHealth { get; private set; }
|
||||
public float attackDamage { get; private set; }
|
||||
|
||||
public UnityEvent OnDeath;
|
||||
public UnityEvent<float> OnTakeDamage;
|
||||
|
||||
private int maxHealth;
|
||||
private int currentHealth;
|
||||
private int attackDamage;
|
||||
|
||||
[SerializeField] private EntityData data;
|
||||
|
||||
|
|
@ -20,30 +16,28 @@ public class Entity : MonoBehaviour
|
|||
attackDamage = data.attackDamage;
|
||||
}
|
||||
|
||||
public virtual void TakeDamage(float damage)
|
||||
public virtual void TakeDamage(int playerAttackDamage)
|
||||
{
|
||||
currentHealth -= damage;
|
||||
OnTakeDamage?.Invoke(damage);
|
||||
currentHealth -= playerAttackDamage;
|
||||
if (currentHealth <= 0)
|
||||
{
|
||||
currentHealth = 0;
|
||||
Die();
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Die()
|
||||
{
|
||||
Destroy(gameObject);
|
||||
OnDeath?.Invoke();
|
||||
}
|
||||
|
||||
public void Heal(float heal)
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (heal < 0) return;
|
||||
currentHealth += heal;
|
||||
if(currentHealth > maxHealth)
|
||||
{
|
||||
currentHealth = maxHealth;
|
||||
}
|
||||
RunAI();
|
||||
}
|
||||
|
||||
protected void RunAI() { }
|
||||
|
||||
|
||||
public int getAttackDamage()
|
||||
{
|
||||
return attackDamage;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ using UnityEngine;
|
|||
[CreateAssetMenu(fileName = "EntityData", menuName = "Scriptable Objects/EntityData")]
|
||||
public class EntityData : ScriptableObject
|
||||
{
|
||||
public string entityName;
|
||||
public float maxHealth;
|
||||
public float attackDamage;
|
||||
public string name;
|
||||
public int maxHealth;
|
||||
public int attackDamage;
|
||||
}
|
||||
|
|
|
|||
50
Assets/Scripts/Player/Player.cs
Normal file
50
Assets/Scripts/Player/Player.cs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class Player : MonoBehaviour
|
||||
{
|
||||
private int currentHealth;
|
||||
private int maxHealth;
|
||||
|
||||
private int maxJumpCount = 2;
|
||||
private int currentJumpCount = 2;
|
||||
|
||||
[SerializeField] private float moveSpeed = 9f;
|
||||
[SerializeField] private float jumpSpeed = 18.2f;
|
||||
[SerializeField] private float jumpCutMultiplier = 0.3f;
|
||||
|
||||
private Rigidbody2D _rigidbody;
|
||||
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_rigidbody = gameObject.GetComponent<Rigidbody2D>();
|
||||
}
|
||||
|
||||
public void Jump()
|
||||
{
|
||||
if (currentJumpCount > 0)
|
||||
{
|
||||
currentJumpCount--;
|
||||
_rigidbody.linearVelocity = new Vector2(_rigidbody.linearVelocity.x, 0);
|
||||
_rigidbody.AddForce(Vector2.up * jumpSpeed, ForceMode2D.Impulse);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Heal(int heal)
|
||||
{
|
||||
if (heal < 0) { return; }
|
||||
|
||||
currentHealth += heal;
|
||||
if (currentHealth > maxHealth)
|
||||
{
|
||||
currentHealth = maxHealth;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
2
Assets/Scripts/Player/Player.cs.meta
Normal file
2
Assets/Scripts/Player/Player.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b68250b34a148164d9a00b31f0af63d8
|
||||
|
|
@ -6,6 +6,12 @@ using UnityEngine.InputSystem;
|
|||
|
||||
public class PlayerController : MonoBehaviour
|
||||
{
|
||||
|
||||
private Player player;
|
||||
|
||||
private int currentHealth;
|
||||
private int maxHealth;
|
||||
|
||||
private Rigidbody2D _rigidbody;
|
||||
private Camera _camera;
|
||||
|
||||
|
|
@ -34,6 +40,7 @@ public class PlayerController : MonoBehaviour
|
|||
|
||||
private void Start()
|
||||
{
|
||||
player = GetComponent<Player>();
|
||||
_rigidbody = gameObject.GetComponent<Rigidbody2D>();
|
||||
_camera = Camera.main;
|
||||
}
|
||||
|
|
@ -70,31 +77,7 @@ public class PlayerController : MonoBehaviour
|
|||
|
||||
private void OnJump(InputValue value)
|
||||
{
|
||||
if (value.isPressed)
|
||||
{
|
||||
if (currentJumpCount > 0)
|
||||
{
|
||||
currentJumpCount--;
|
||||
jumpStartTime = Time.time;
|
||||
if (jumpCutRoutine != null) StopCoroutine(jumpCutRoutine);
|
||||
_rigidbody.linearVelocity = new Vector2(_rigidbody.linearVelocity.x, 0);
|
||||
_rigidbody.AddForce(Vector2.up * jumpSpeed, ForceMode2D.Impulse);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
float timeElapsed = Time.time - jumpStartTime;
|
||||
|
||||
if (timeElapsed >= minJumpDuration)
|
||||
{
|
||||
CutJumpVelocity();
|
||||
}
|
||||
else
|
||||
{
|
||||
float delay = minJumpDuration - timeElapsed;
|
||||
jumpCutRoutine = StartCoroutine(DelayedJumpCut(delay));
|
||||
}
|
||||
}
|
||||
player.Jump();
|
||||
}
|
||||
|
||||
private void NormalAttack()
|
||||
|
|
@ -216,4 +199,6 @@ public class PlayerController : MonoBehaviour
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user