too many if statements
This commit is contained in:
parent
533f137c48
commit
17b1a1e367
7 changed files with 55 additions and 20 deletions
|
|
@ -182,6 +182,9 @@ MonoBehaviour:
|
||||||
moveAnimSpeed: 10
|
moveAnimSpeed: 10
|
||||||
canMove: 1
|
canMove: 1
|
||||||
invincible: 0
|
invincible: 0
|
||||||
|
spriteRenderers:
|
||||||
|
- {fileID: 6433073964262250546}
|
||||||
|
damageColorChangeSpeed: 4
|
||||||
turnSpeed: 1
|
turnSpeed: 1
|
||||||
minimumAttackRange: 1.5
|
minimumAttackRange: 1.5
|
||||||
damage: 10
|
damage: 10
|
||||||
|
|
|
||||||
|
|
@ -436,6 +436,9 @@ MonoBehaviour:
|
||||||
moveAnimSpeed: 10
|
moveAnimSpeed: 10
|
||||||
canMove: 1
|
canMove: 1
|
||||||
invincible: 0
|
invincible: 0
|
||||||
|
spriteRenderers:
|
||||||
|
- {fileID: 3017941309338641158}
|
||||||
|
damageColorChangeSpeed: 4
|
||||||
hasMoved: 0
|
hasMoved: 0
|
||||||
hasAttacked: 0
|
hasAttacked: 0
|
||||||
weapons:
|
weapons:
|
||||||
|
|
|
||||||
|
|
@ -48,36 +48,36 @@ public class ActionUIHandler : MonoBehaviour
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateUI()
|
public void UpdateUI()
|
||||||
{
|
|
||||||
if (!selectedEntity.hasAttacked)
|
|
||||||
{
|
{
|
||||||
if (selectedEntity.currentWeapon.TryGetComponent(out RangedWeapon isRanged))
|
if (selectedEntity.currentWeapon.TryGetComponent(out RangedWeapon isRanged))
|
||||||
{
|
{
|
||||||
possibleRanged = isRanged;
|
possibleRanged = isRanged;
|
||||||
}
|
}
|
||||||
if (!isRanged || !isRanged.fired)
|
if ((!isRanged || !isRanged.fired) && !selectedEntity.hasAttacked)
|
||||||
{
|
{
|
||||||
attackButton.gameObject.SetActive(true);
|
attackButton.gameObject.SetActive(true);
|
||||||
|
reloadButton.gameObject.SetActive(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
attackButton.gameObject.SetActive(false);
|
attackButton.gameObject.SetActive(false);
|
||||||
}
|
if (isRanged && isRanged.fired)
|
||||||
|
{
|
||||||
|
if (selectedEntity.hasMoved || selectedEntity.hasAttacked)
|
||||||
|
{
|
||||||
|
reloadButton.gameObject.SetActive(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
attackButton.gameObject.SetActive(false);
|
reloadButton.gameObject.SetActive(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!selectedEntity.hasMoved || !selectedEntity.hasAttacked)
|
if (!selectedEntity.hasMoved || !selectedEntity.hasAttacked)
|
||||||
{
|
{
|
||||||
moveButton.gameObject.SetActive(true);
|
moveButton.gameObject.SetActive(true);
|
||||||
switchButton.gameObject.SetActive(true);
|
switchButton.gameObject.SetActive(true);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
reloadButton.gameObject.SetActive(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selectedEntity.hasAttacked && selectedEntity.hasMoved)
|
if (selectedEntity.hasAttacked && selectedEntity.hasMoved)
|
||||||
{
|
{
|
||||||
HideUI();
|
HideUI();
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ using UnityEngine;
|
||||||
|
|
||||||
public class Enemy : Entity
|
public class Enemy : Entity
|
||||||
{
|
{
|
||||||
|
[Header("Enemy Stats")]
|
||||||
public int turnSpeed;
|
public int turnSpeed;
|
||||||
public float minimumAttackRange;
|
public float minimumAttackRange;
|
||||||
private PlayerEntity closestPlayer;
|
private PlayerEntity closestPlayer;
|
||||||
|
|
|
||||||
|
|
@ -11,15 +11,20 @@ public class Entity : MonoBehaviour
|
||||||
[Header("Movement")]
|
[Header("Movement")]
|
||||||
public int maxMovement;
|
public int maxMovement;
|
||||||
public TileObject currentTile;
|
public TileObject currentTile;
|
||||||
public float moveAnimSpeed;
|
[SerializeField] private float moveAnimSpeed;
|
||||||
|
|
||||||
[Header("Flags")]
|
[Header("Flags")]
|
||||||
public bool canMove = true;
|
public bool canMove = true;
|
||||||
public bool invincible;
|
public bool invincible;
|
||||||
|
|
||||||
|
[Header("Animation")]
|
||||||
|
[SerializeField] private SpriteRenderer[] spriteRenderers;
|
||||||
|
[SerializeField] private float damageColorChangeSpeed;
|
||||||
|
|
||||||
public virtual void TakeDamage(float damage)
|
public virtual void TakeDamage(float damage)
|
||||||
{
|
{
|
||||||
health -= damage;
|
health -= damage;
|
||||||
|
StartCoroutine(DamageAnimation());
|
||||||
if (health <= 0)
|
if (health <= 0)
|
||||||
{
|
{
|
||||||
OnKillEffects();
|
OnKillEffects();
|
||||||
|
|
@ -61,4 +66,20 @@ public class Entity : MonoBehaviour
|
||||||
}
|
}
|
||||||
FinishedMovement();
|
FinishedMovement();
|
||||||
}
|
}
|
||||||
|
private IEnumerator DamageAnimation()
|
||||||
|
{
|
||||||
|
float currentState = 0;
|
||||||
|
while (currentState < 1)
|
||||||
|
{
|
||||||
|
currentState += Time.deltaTime * damageColorChangeSpeed;
|
||||||
|
foreach (SpriteRenderer spritepart in spriteRenderers)
|
||||||
|
{
|
||||||
|
if (spritepart)
|
||||||
|
{
|
||||||
|
spritepart.color = Color.Lerp(Color.gray, Color.white, currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
yield return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@ public class RangedWeapon : Weapon
|
||||||
{
|
{
|
||||||
private Camera cam;
|
private Camera cam;
|
||||||
private Vector3 mousePos;
|
private Vector3 mousePos;
|
||||||
|
[Header("Ranged Weapon Specifics")]
|
||||||
public bool fired;
|
public bool fired;
|
||||||
public bool isAiming;
|
|
||||||
[SerializeField] private Projectile projectile;
|
[SerializeField] private Projectile projectile;
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,15 @@ using UnityEngine;
|
||||||
|
|
||||||
public class Weapon : MonoBehaviour
|
public class Weapon : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
[Header("Identification")]
|
||||||
public string weaponName;
|
public string weaponName;
|
||||||
|
[Header("Cache")]
|
||||||
|
public bool isAiming;
|
||||||
public PlayerEntity thisEntity;
|
public PlayerEntity thisEntity;
|
||||||
|
|
||||||
|
[Header("Stats")]
|
||||||
|
public float damage;
|
||||||
|
|
||||||
public virtual void TryAttack()
|
public virtual void TryAttack()
|
||||||
{
|
{
|
||||||
AttackEffects();
|
AttackEffects();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue