Soldier is a child of base

This commit is contained in:
Krzysztof Rudnicki 2022-05-23 13:18:37 +02:00
parent b41c920fb2
commit f9804b48bb
4 changed files with 17 additions and 68 deletions

View File

@ -64,7 +64,7 @@ Rigidbody:
m_UseGravity: 0 m_UseGravity: 0
m_IsKinematic: 0 m_IsKinematic: 0
m_Interpolate: 0 m_Interpolate: 0
m_Constraints: 0 m_Constraints: 126
m_CollisionDetection: 0 m_CollisionDetection: 0
--- !u!114 &-4006122134844739070 --- !u!114 &-4006122134844739070
MonoBehaviour: MonoBehaviour:

View File

@ -64,7 +64,7 @@ Rigidbody:
m_UseGravity: 0 m_UseGravity: 0
m_IsKinematic: 0 m_IsKinematic: 0
m_Interpolate: 0 m_Interpolate: 0
m_Constraints: 0 m_Constraints: 126
m_CollisionDetection: 0 m_CollisionDetection: 0
--- !u!114 &1033819704020761458 --- !u!114 &1033819704020761458
MonoBehaviour: MonoBehaviour:
@ -78,9 +78,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: d34caf35d0ce610f8bc87cf815ba1915, type: 3} m_Script: {fileID: 11500000, guid: d34caf35d0ce610f8bc87cf815ba1915, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
target: {fileID: 0}
enemyType: 0
ourType: 0
maxHealthPoints: 100 maxHealthPoints: 100
healthPoints: 100 healthPoints: 100
rangeAttack: 3 rangeAttack: 3
@ -90,7 +87,13 @@ MonoBehaviour:
lastAttackTick: -1 lastAttackTick: -1
nameText: {fileID: 6838251604148675782} nameText: {fileID: 6838251604148675782}
healthPointsText: {fileID: 8012357605284019061} healthPointsText: {fileID: 8012357605284019061}
target: {fileID: 0}
enemyType: 0
ourType: 0
movementDestination: {x: 0, y: 0} movementDestination: {x: 0, y: 0}
onDeath:
m_PersistentCalls:
m_Calls: []
--- !u!1 &1997457243244158843 --- !u!1 &1997457243244158843
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -10,7 +10,7 @@ public class Base : MonoBehaviour
Ally, Ally,
Enemy Enemy
} }
[SerializeField] private SoldierType ourType; [SerializeField] protected SoldierType ourType;
[SerializeField] private float maxHealthPoints = 100; [SerializeField] private float maxHealthPoints = 100;
[SerializeField] private float healthPoints = 100; [SerializeField] private float healthPoints = 100;
@ -23,7 +23,7 @@ public class Base : MonoBehaviour
} }
// Start is called before the first frame update // Start is called before the first frame update
void Start(){ protected void Start(){
healthPoints = maxHealthPoints; // initialize health healthPoints = maxHealthPoints; // initialize health
UpdateHPDisplay(); UpdateHPDisplay();
@ -51,11 +51,11 @@ public class Base : MonoBehaviour
ourType = type; ourType = type;
} }
private void OnDestroy() protected void OnDestroy()
{ {
Debug.Log("Soldier: " + ourType.ToString() + " has died", gameObject); Debug.Log("Soldier: " + ourType.ToString() + " has died", gameObject);
} }
private void ReduceHP(float damage) protected void ReduceHP(float damage)
{ {
healthPoints -= damage; healthPoints -= damage;
@ -66,7 +66,7 @@ public class Base : MonoBehaviour
Debug.Log("I took damage, my HP is now: " + healthPoints + " noooo!!!!", gameObject); Debug.Log("I took damage, my HP is now: " + healthPoints + " noooo!!!!", gameObject);
} }
private void UpdateHPDisplay() protected void UpdateHPDisplay()
{ {
healthPointsText.text = healthPoints.ToString() + "/" + maxHealthPoints.ToString(); healthPointsText.text = healthPoints.ToString() + "/" + maxHealthPoints.ToString();
} }

View File

@ -4,7 +4,7 @@ using TMPro;
using UnityEngine; using UnityEngine;
using UnityEngine.Events; using UnityEngine.Events;
public class Soldier : MonoBehaviour public class Soldier : Base
{ {
private Queue<Action> actions = new Queue<Action>(); private Queue<Action> actions = new Queue<Action>();
private Queue<Action> interrupts = new Queue<Action>(); private Queue<Action> interrupts = new Queue<Action>();
@ -40,26 +40,17 @@ public class Soldier : MonoBehaviour
interrupts.Enqueue(new Movement()); // force soldier to find path to the new destination interrupts.Enqueue(new Movement()); // force soldier to find path to the new destination
} }
#endregion #endregion
public enum SoldierType
{
Ally,
Enemy
}
[Header("Values")] [Header("Values")]
[SerializeField] private float maxHealthPoints = 10;
[SerializeField] private float healthPoints = 1;
[SerializeField] private float rangeAttack = 100; [SerializeField] private float rangeAttack = 100;
[SerializeField] private float rangeView = 1; [SerializeField] private float rangeView = 1;
[SerializeField] private float damageAttack = 1; [SerializeField] private float damageAttack = 1;
[SerializeField] private int speedAttack = 1; // ticks between attacks [SerializeField] private int speedAttack = 1; // ticks between attacks
[SerializeField] private int lastAttackTick = -1; [SerializeField] private int lastAttackTick = -1;
[Header("References")] [Header("References")]
[SerializeField] private TMP_Text nameText = null;
[SerializeField] private TMP_Text healthPointsText = null;
[Header("Do-not-change-in-game values")] [Header("Do-not-change-in-game values")]
[SerializeField] private Soldier target; [SerializeField] private Soldier target;
[SerializeField] private SoldierType enemyType; [SerializeField] private SoldierType enemyType;
[SerializeField] private SoldierType ourType;
[SerializeField] private Vector2Int movementDestination = Vector2Int.zero; [SerializeField] private Vector2Int movementDestination = Vector2Int.zero;
@ -67,39 +58,11 @@ public class Soldier : MonoBehaviour
[HideInInspector] public UnityEvent onDeath = new UnityEvent(); [HideInInspector] public UnityEvent onDeath = new UnityEvent();
public SoldierType TempGetOwnType()
{
return ourType;
}
// Start is called before the first frame update // Start is called before the first frame update
void Start(){ void Start(){
healthPoints = maxHealthPoints; // initialize health base.Start();
UpdateHPDisplay();
setEnemyTag(); setEnemyTag();
Debug.Log("Soldier: " + ourType.ToString() + " has appeared", gameObject);
switch (ourType)
{
case SoldierType.Ally:
nameText.text = "Ally";
nameText.color = Color.blue;
break;
case SoldierType.Enemy:
nameText.text = "Enemy";
nameText.color = Color.red;
break;
default:
nameText.text = "how did we get here (forever)";
nameText.color = new Color(255, 192, 203);
break;
}
}
public void setOwnTag(SoldierType type)
{
ourType = type;
} }
public void setEnemyTag() public void setEnemyTag()
@ -115,10 +78,9 @@ public class Soldier : MonoBehaviour
private void OnDestroy() private void OnDestroy()
{ {
base.OnDestroy();
TickSystem.OnTick -= HandleTick; TickSystem.OnTick -= HandleTick;
onDeath.Invoke(); onDeath.Invoke();
Debug.Log("Soldier: " + ourType.ToString() + " has died", gameObject);
} }
private void HandleTick(TickSystem.OnTickEventArgs tickEventArgs) private void HandleTick(TickSystem.OnTickEventArgs tickEventArgs)
@ -195,20 +157,4 @@ public class Soldier : MonoBehaviour
} }
*/ */
private void ReduceHP(float damage)
{
healthPoints -= damage;
if (healthPoints <= 0)
Destroy(gameObject);
UpdateHPDisplay();
Debug.Log("I took damage, oh my HP is now: " + healthPoints + " noooo!!!!", gameObject);
}
private void UpdateHPDisplay()
{
healthPointsText.text = healthPoints.ToString() + "/" + maxHealthPoints.ToString();
}
} }