private void Awake() { animator = this.GetComponentOrFail <Animator>(); collider2d = this.GetComponentOrFail <Collider2D>(); m_State = SwitchBlockState.Ground; // must be done before SwitchBlockManager.Setup as it may call OnSwitchActiveColor back collider2d.enabled = false; }
/// Method called on reception of the event 'active color has changed' /// Change the state accordingly private void OnSwitchActiveColor(GameColor newActiveColor) { // if the new active color and the previous active color are both this block's color, // or both not this block's color no need to change the state bool wasActive = animator.GetBool(AnimHash_Active); bool shouldBeActive = color == newActiveColor; if (wasActive ^ shouldBeActive) { // the current state of the block is not was it should be, update it with collider and animation m_State = shouldBeActive ? SwitchBlockState.Ground : SwitchBlockState.Wall; collider2d.enabled = !shouldBeActive; animator.SetBool(AnimHash_Active, shouldBeActive); } }