Only alive participants can act
This commit is contained in:
parent
a5a96edf25
commit
adc84f9aba
5 changed files with 44 additions and 8 deletions
|
|
@ -9,10 +9,12 @@ public class BattleParticipantSprite : MonoBehaviour
|
|||
|
||||
private BattlePlayerControls playerControls;
|
||||
private BattleParticipant participant;
|
||||
private bool removedFromBattle;
|
||||
|
||||
public void Init(BattlePlayerControls playerControls, BattleParticipant participant) {
|
||||
this.playerControls = playerControls;
|
||||
this.participant = participant;
|
||||
this.removedFromBattle = false;
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
|
|
@ -22,20 +24,22 @@ public class BattleParticipantSprite : MonoBehaviour
|
|||
|
||||
// Update is called once per frame
|
||||
void Update() {
|
||||
if (colorChanged && !this.playerControls.CouldTarget(participant)) {
|
||||
if (this.colorChanged && !this.playerControls.CouldTarget(participant)) {
|
||||
OnMouseExit();
|
||||
}
|
||||
}
|
||||
|
||||
void OnMouseDown() {
|
||||
OnSpriteClicked(participant);
|
||||
if (!this.removedFromBattle) {
|
||||
OnSpriteClicked(participant);
|
||||
}
|
||||
}
|
||||
|
||||
private Color savedColor;
|
||||
private bool colorChanged;
|
||||
|
||||
void OnMouseEnter() {
|
||||
if (this.playerControls.CouldTarget(participant)) {
|
||||
if (!this.removedFromBattle && this.playerControls.CouldTarget(participant)) {
|
||||
SpriteRenderer sprite = GetComponent<SpriteRenderer>();
|
||||
this.savedColor = sprite.color;
|
||||
sprite.color = Color.Lerp(this.savedColor, Color.white, .5f);
|
||||
|
|
@ -50,4 +54,19 @@ public class BattleParticipantSprite : MonoBehaviour
|
|||
this.colorChanged = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void NotifyDeath(BattleParticipant deadParticipant) {
|
||||
if (deadParticipant != this.participant) {
|
||||
throw new System.InvalidOperationException(
|
||||
"BattleParticipantSprite received NotifyDeath from another battle participant.");
|
||||
}
|
||||
|
||||
if (!this.removedFromBattle) {
|
||||
SpriteRenderer sprite = GetComponent<SpriteRenderer>();
|
||||
sprite.enabled = false;
|
||||
BoxCollider2D collider = GetComponent<BoxCollider2D>();
|
||||
collider.enabled = false;
|
||||
this.removedFromBattle = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue