IEnumerator MoveObject() { bool isMovingPlayer = ObjectToMove == Player.Instance.gameObject; Collider2D result = Physics2D.OverlapPoint( new Vector2(ObjectToMove.transform.position.x, ObjectToMove.transform.position.y) + this.Direction, layerMask); GameObject[] chains = null; PullStateComponent psc = PreviousState.GetComponent <PullStateComponent>(); if (psc != null) { chains = new GameObject[psc.chains.Count]; psc.chains.CopyTo(chains, 0); } while (result == null) { //move Vector3 oldPosition = ObjectToMove.transform.position; ObjectToMove.transform.position = new Vector3( ObjectToMove.transform.position.x + this.Direction.x, ObjectToMove.transform.position.y + this.Direction.y); if (chains != null) { foreach (GameObject chain in chains) { chain.transform.position = new Vector3( chain.transform.position.x + this.Direction.x, chain.transform.position.y + this.Direction.y); } } result = Physics2D.OverlapPoint( new Vector2(ObjectToMove.transform.position.x, ObjectToMove.transform.position.y) + this.Direction, layerMask); yield return(isMovingPlayer ? Tick.Instance.Advance() : Tick.Instance.DontAdvance()); } this.shouldExit = true; }
private void Awake() { this.pullStateComponent = this.pullState.GetComponent <PullStateComponent>(); }