private void ChangeStateIfNotNull(HexagonBaseState newState) { if (newState != null) { ChangeState(newState); } }
void Awake() { if (hexagonLayer == 0) { hexagonLayer = 1 << LayerMask.NameToLayer("Hexagon"); } staticState = new HexagonStaticState(this); idleState = new HexagonIdleState(this); borderWallState = new HexagonBorderWallState(this); movingState = new HexagonMovingState(this); enterExitState = new HexagonEnterExitState(this); infectedState = new HexagonInfectedState(this); warningState = new HexagonWarningState(this); belowAttackState = new HexagonBelowAttackState(this); belowAttackAdjacentState = new HexagonBelowAttackAdjacentState(this); belowAttackWallState = new HexagonBelowAttackWallState(this); aboveAttackState = new HexagonAboveAttackState(this); aboveAttackAdjacentState = new HexagonAboveAttackAdjacentState(this); meteorAttackState = new HexagonMeteorAttackState(this); minDistanceToPlayer = minHexagonsToPlayer * DISTANCE_BETWEEN_HEXAGONS; sphereCollider = GetComponent <SphereCollider>(); geometryOffset = transform.FindDeepChild("GeometryOffset").gameObject; geometryOriginalY = geometryOffset.transform.position.y; spawnPoint = transform.FindDeepChild("SpawnPoint").gameObject; wormProbesInRange = 0; //enemyProbesInRange = 0; enemiesInRange.Clear(); playerProbesInRange = 0; CheckNeighbours(); turret = null; if (isStatic) { Transform turretTrf = transform.FindDeepChild("Turret"); if (turretTrf != null) { turret = turretTrf.GetComponent <TurretAIBehaviour>(); } else { columnColliders.transform.localPosition = new Vector3(0f, 10f, 0f); } currentState = staticState; navMeshObstacles.SetActive(true); columnRend.sharedMaterial = floorStaticMat; } else { currentState = idleState; navMeshObstacles.SetActive(false); } }
// Update is called once per frame void Update() { if (currentState != null) { HexagonBaseState newState = currentState.Update(); if (newState != null) { ChangeState(newState); } } }
private void ChangeState(HexagonBaseState newState) { if (isStatic) { return; } if (currentState != null) { //Debug.Log("Hexagon Exiting: " + currentState.GetType().Name); currentState.OnStateExit(); } currentState = newState; if (currentState != null) { //Debug.Log("Hexagon Entering: " + currentState.GetType().Name); currentState.OnStateEnter(); } }