-
-
Save e-sarkis/7c818e8db0eba7da206d1267efff5645 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BombFish : MonoBehaviour | |
{ | |
public enum State { Enter, Attack, Exit }; | |
public State currentState; | |
private EnemyController EC; | |
public enum DropStrategy { DropOnPlayer, DropOnDestination, DropXCoordinate } | |
public DropStrategy Drop; | |
public float XTarget = 0f; | |
private Bomb ourBomb; | |
private Transform PlayerTransform; | |
void Awake () | |
{ | |
EC = GetComponent<EnemyController>(); | |
ourBomb = GetComponentInChildren<Bomb>(); | |
currentState = State.Enter; | |
PlayerTransform = GameObject.FindGameObjectWithTag("Player").transform; | |
} | |
void Update () | |
{ | |
switch (currentState) | |
{ | |
case State.Enter: | |
EnterUpdate(); | |
break; | |
case State.Attack: | |
AttackUpdate(); | |
break; | |
case State.Exit: | |
ExitUpdate(); | |
break; | |
default: | |
break; | |
} | |
} | |
private void ExitUpdate() | |
{ | |
// Just keep swimming | |
} | |
private void AttackUpdate() | |
{ | |
DropBomb(); | |
currentState = State.Exit; | |
} | |
private void EnterUpdate() | |
{ | |
switch (Drop) | |
{ | |
case DropStrategy.DropOnPlayer: | |
if (Mathf.Abs(PlayerTransform.position.x - transform.position.x) < .5f) | |
{ | |
currentState = State.Attack; | |
} | |
break; | |
case DropStrategy.DropXCoordinate: | |
if (Mathf.Abs(XTarget - transform.position.x) < .5f) | |
{ | |
currentState = State.Attack; | |
} | |
break; | |
default: | |
// Drop Destination | |
if (EC.atDestinationX && EC.atDestinationY) | |
{ | |
currentState = State.Attack; | |
} | |
break; | |
} | |
} | |
private void DropBomb() | |
{ | |
ourBomb.ActivateBomb(); | |
int xVector = 0; | |
if (transform.localScale.x < 0) | |
{ | |
xVector = -1; | |
} | |
else | |
{ | |
xVector = 1; | |
} | |
EC.SetMovementVector(xVector, 0); | |
currentState = State.Exit; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment