public void CheckBounderies() { if (!MovingTowardsBounds()) { if (aiBase.transform.position.x < playArea.min.x || aiBase.transform.position.x > playArea.max.x) { aiBase.aiMovement.InvertXDirection(); AIVisuals.FlipSpriteOnX(aiBase.mySpriteRenderer, aiBase.waterParticles.GetComponent <SpriteRenderer>(), aiBase.aiMovement.direction.x, aiBase.myType); return; } if (aiBase.transform.position.y < playArea.min.y || aiBase.transform.position.y > playArea.max.y - 5) { aiBase.aiMovement.InvertYDirection(); return; } } if (aiBase.transform.position.y > playArea.max.y - 10 && aiBase.body.velocity.y > 0) { aiBase.aiMovement.InvertYDirection(); } }
protected void SetUp() { GetReferences(); aiMovement = new AIMovement(this); aiCheckStatus = new AICheckStatus(this); if (myType != EnemyType.Floater && myType != EnemyType.Surfer) { AIVisuals.FlipSpriteOnX(mySpriteRenderer, waterParticles.GetComponent <SpriteRenderer>(), aiMovement.direction.x, myType); } }
void OnCollisionEnter2D(Collision2D collision) { if (aiCheckStatus.DidNotHitEnemy(collision)) { if (aiCheckStatus.IsThistoTheRightOfMe(collision) || aiCheckStatus.IsThisToTheLeftOfMe(collision)) { aiMovement.InvertXDirection(); if (myType != EnemyType.Floater && myType != EnemyType.Surfer) { AIVisuals.FlipSpriteOnX(mySpriteRenderer, waterParticles.GetComponent <SpriteRenderer>(), aiMovement.direction.x, myType); } } if (aiCheckStatus.IsThisAboveMe(collision) || aiCheckStatus.IsThisBeneathMe(collision)) { aiMovement.InvertYDirection(); } } else if (aiCheckStatus.HitEnemy(collision) && aiCheckStatus.IsWhatIHitBigger(collision)) { if (aiCheckStatus.IsThistoTheRightOfMe(collision) || aiCheckStatus.IsThisToTheLeftOfMe(collision)) { aiMovement.InvertXDirection(); if (myType != EnemyType.Floater && myType != EnemyType.Surfer) { AIVisuals.FlipSpriteOnX(mySpriteRenderer, waterParticles.GetComponent <SpriteRenderer>(), aiMovement.direction.x, myType); } } if (aiCheckStatus.IsThisAboveMe(collision) || aiCheckStatus.IsThisBeneathMe(collision)) { aiMovement.InvertYDirection(); } } }