void GetTouch( ) { //Get all collider contact with stingray bool bTouchPlayer = false; List <Collider2D> colliders = new List <Collider2D> ( ); col.OverlapCollider(new ContactFilter2D( ), colliders); foreach (Collider2D collider in colliders) { //if ground under stingray set verticalposition up //else change direction due to the ground position if (collider.gameObject.layer == LayerMask.NameToLayer("Ground")) { if (GalaxySeeker.Physics2D.IsUnder(Parent.tf.position, collider.transform.position)) { horiLoopMove.SetVerticalPos(horiLoopMove.VerticalPos + sinkSpeed * Time.fixedDeltaTime); } else if (GalaxySeeker.Physics2D.IsRight(Parent.tf.position, collider.transform.position)) { horiLoopMove.IsFacingRight = false; } else { horiLoopMove.IsFacingRight = true; } } //if touch player and player is above it start to sink //Also set stingray transform as player parent if (collider.gameObject.tag == "Player") { if (GalaxySeeker.Physics2D.IsAbove(Parent.tf.position, collider.transform.position)) { targetTransform = collider.transform; targetTransform.SetParent(Parent.tf); horiLoopMove.SetVerticalPos(horiLoopMove.VerticalPos - sinkSpeed * Time.fixedDeltaTime); bTouchPlayer = true; } } } if (bTouchPlayer && !asg.Anim.IsPlaying(sinkAnim.name)) { asg.Anim.Play(sinkAnim.name); } //if doesn't touchPlayer set targetTransform to null if (!bTouchPlayer && targetTransform) { targetTransform.SetParent(null); targetTransform = null; asg.Anim.Play(asg.Anim.clip.name); } }
void GetTouch( ) { bool bTouchPlayer = false; List <Collider2D> colliders = new List <Collider2D> ( ); col.OverlapCollider(new ContactFilter2D( ), colliders); foreach (Collider2D collider in colliders) { //if the collider is ground enter this state if (collider.gameObject.layer == LayerMask.NameToLayer("Ground")) { //if now use pingPongMove will change its direction due to direction of collider if (currentMove == pingPongMove) { if (GalaxySeeker.Physics2D.IsRight(Parent.tf.position, collider.transform.position)) { pingPongMove.IsFacingRight = false; } else if (GalaxySeeker.Physics2D.IsRight(Parent.tf.position, collider.transform.position)) { pingPongMove.IsFacingRight = true; } } //if now use rangeMove will try to find another target position else if (currentMove == rangeMove) { rangeMove.FindNewTargetPos( ); } } //if collider with player and player stand on it change moveMode to rangeMove if (collider.gameObject.tag == "Player") { if (GalaxySeeker.Physics2D.IsAbove(Parent.tf.position, collider.transform.position)) { targetTransform = collider.transform; targetTransform.SetParent(Parent.tf); bTouchPlayer = true; currentMove = rangeMove; if (!rasg.Anim.IsPlaying(rageAnim.name)) { rasg.Anim.Play(rageAnim.name); } } } } // if player out of it set parent to null if (!bTouchPlayer && targetTransform) { targetTransform.SetParent(null); targetTransform = null; pingPongMove.SetVerticalPos(Parent.tf.position.y); currentMove = pingPongMove; rasg.Anim.Play(rasg.Anim.clip.name); } }