Generic class of enemy & first enemy: Mayor
This commit is contained in:
@@ -16,6 +16,7 @@ GameObject:
|
||||
- component: {fileID: 8338184184584571871}
|
||||
- component: {fileID: 3787322971358149925}
|
||||
- component: {fileID: 7397454076540391921}
|
||||
- component: {fileID: 8339747699126584523}
|
||||
m_Layer: 0
|
||||
m_Name: Player
|
||||
m_TagString: Player
|
||||
@@ -157,16 +158,16 @@ BoxCollider2D:
|
||||
m_LayerOverridePriority: 0
|
||||
m_ForceSendLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_Bits: 55
|
||||
m_ForceReceiveLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_Bits: 55
|
||||
m_ContactCaptureLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_Bits: 55
|
||||
m_CallbackLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_Bits: 55
|
||||
m_IsTrigger: 0
|
||||
m_UsedByEffector: 0
|
||||
m_UsedByComposite: 0
|
||||
@@ -208,10 +209,10 @@ CircleCollider2D:
|
||||
m_Bits: 4294967295
|
||||
m_ContactCaptureLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_Bits: 8
|
||||
m_CallbackLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_Bits: 8
|
||||
m_IsTrigger: 1
|
||||
m_UsedByEffector: 0
|
||||
m_UsedByComposite: 0
|
||||
@@ -242,3 +243,19 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 76eec47d6b942ad4ab792b7022c07bb1, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!114 &8339747699126584523
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1784956759114531697}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: d8afe5a349c86994f8ddacd37ce22ae3, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
Health: 100
|
||||
Speed: 2
|
||||
Exp: 0
|
||||
Level: 1
|
||||
|
||||
@@ -4,8 +4,9 @@ using UnityEngine;
|
||||
|
||||
public class PlayerManager : MonoBehaviour
|
||||
{
|
||||
public float Health = 100f;
|
||||
public float Speed = 10f;
|
||||
public int Health = 100;
|
||||
public int MaxHealth = 100;
|
||||
public float Speed = 2f;
|
||||
public int Exp = 0;
|
||||
public int Level = 1;
|
||||
|
||||
@@ -19,4 +20,27 @@ public class PlayerManager : MonoBehaviour
|
||||
Level++;
|
||||
}
|
||||
}
|
||||
|
||||
public void TakeDamage(int value)
|
||||
{
|
||||
Health -= value;
|
||||
if (Health < 0)
|
||||
{
|
||||
Health = 0;
|
||||
|
||||
// Death animation + menu
|
||||
} else
|
||||
{
|
||||
// Damage animation
|
||||
}
|
||||
}
|
||||
|
||||
public void Heal(int value)
|
||||
{
|
||||
Health += value;
|
||||
if (Health > MaxHealth)
|
||||
{
|
||||
Health = MaxHealth;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(SpriteRenderer)), RequireComponent(typeof(Animator))]
|
||||
[RequireComponent(typeof(SpriteRenderer)), RequireComponent(typeof(Animator)), RequireComponent(typeof(PlayerManager))]
|
||||
public class PlayerMovements : MonoBehaviour
|
||||
{
|
||||
private readonly float _speed = .15f;
|
||||
|
||||
private SpriteRenderer _sr;
|
||||
private Animator _animator;
|
||||
private PlayerManager _pm;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_sr = GetComponent<SpriteRenderer>();
|
||||
_animator = GetComponent<Animator>();
|
||||
_pm = GetComponent<PlayerManager>();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
/** --- Move player along 2D axis ----------------------------------*/
|
||||
float moveH = Input.GetAxis("Horizontal") * _speed;
|
||||
float moveV = Input.GetAxis("Vertical") * _speed;
|
||||
float moveH = Input.GetAxis("Horizontal") * _pm.Speed * Time.deltaTime;
|
||||
float moveV = Input.GetAxis("Vertical") * _pm.Speed * Time.deltaTime;
|
||||
|
||||
transform.Translate(new Vector2(moveH, moveV));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user