public void MoveAction(Groundy groundy) { Vector2 moveQuantity = Vector2.right * groundy.moveSpeed * Time.deltaTime; Vector3 noZQuantity = new Vector3(moveQuantity.x, moveQuantity.y, 0f); groundy.transform.Translate(noZQuantity); }
public virtual bool CheckTransitionToMoving(Groundy groundy) { InvertDirectionIfNeeded(groundy); groundy.TransitionToState(groundy.MovingState); return(true); }
public override void Update(Groundy groundy) { if (CheckTransitionToMoving(groundy)) { return; } base.MoveAction(groundy); }
public virtual bool CheckTransitionToDying(Groundy groundy) { if (groundy.hp <= 0) { groundy.TransitionToState(groundy.DyingState); return(true); } return(false); }
public override bool CheckTransitionToMoving(Groundy groundy) { if (!ThereIsGroundToWalk(groundy) || ReachedObstacle(groundy)) { groundy.needToTurn = true; base.CheckTransitionToMoving(groundy); return(true); } return(false); }
bool ThereIsGroundToWalk(Groundy groundy) { RaycastHit2D[] groundRay = Physics2D.RaycastAll(groundy.groundTransform.position, Vector2.down, distanceToCheckGround); foreach (var obj in groundRay) { if (obj.collider != null && obj.collider.CompareTag("Ground")) { return(true); } } return(false); }
public void InvertDirectionIfNeeded(Groundy groundy) { if (groundy.needToTurn) { if (groundy.transform.eulerAngles.y == 0) { groundy.transform.eulerAngles = new Vector3(0f, 180f, 0f); } else if (groundy.transform.eulerAngles.y == 180) { groundy.transform.eulerAngles = new Vector3(0f, 0f, 0f); } } groundy.needToTurn = false; }
public override void Update(Groundy groundy) { if (base.CheckTransitionToDying(groundy)) { return; } if (hitTimer >= 0) { hitTimer -= Time.deltaTime; return; } if (base.CheckTransitionToMoving(groundy)) { return; } }
bool ReachedObstacle(Groundy groundy) { Vector2 direction = CalculateDirection(groundy); RaycastHit2D[] frontRay = Physics2D.RaycastAll(groundy.frontTransform.position, direction, distanceToCheckObstacle); foreach (var obj in frontRay) { if (obj.collider != null) { bool isWall = obj.collider.CompareTag("Ground"); bool hasHitObstacle = isWall; if (hasHitObstacle) { return(true); } } } return(false); }
private void OnTriggerEnter2D(Collider2D other) { GameObject otherObj = other.gameObject; if (otherObj.CompareTag("Groundy")) { Groundy groundy = otherObj.GetComponent<Groundy>(); if (groundy.hp > 0) { // groundy.dieParticles.transform.parent = null; // groundy.dieParticles.transform.position = groundy.transform.position; // groundy.dieParticles.Play(); hitParticles.transform.parent = null; hitParticles.transform.position = transform.position; hitParticles.transform.localScale = new Vector3(1, 1, 1); hitParticles.Play(); groundy.TakeDamage(); } Destroy(gameObject); } else if (otherObj.CompareTag("Fly")) { Fly fly = otherObj.GetComponent<Fly>(); if (fly.hp > 0) { hitParticles.transform.parent = null; hitParticles.transform.position = transform.position; hitParticles.transform.localScale = new Vector3(1, 1, 1); hitParticles.Play(); // fly.dieParticles.transform.parent = null; // fly.dieParticles.transform.position = fly.transform.position; // fly.dieParticles.Play(); fly.TakeDamage(); } Destroy(gameObject); } else if (otherObj.CompareTag("Ground")) { // taca partículas Destroy(gameObject); } }
public abstract void Update(Groundy groundy);
void BeingHitAction(Groundy groundy) { groundy.rb.velocity = Vector2.zero; groundy.spriteRenderer.color = new Color(1, 0, 0, 1); }
public override void EnterState(Groundy groundy) { // Manager.audio.Play("EnemyHit"); Setup(groundy); BeingHitAction(groundy); }
public override void EnterState(Groundy groundy) { Manager.audio.Play("enemy_dying"); groundy.dieParticles.Play(); Enemy.DieAction(groundy.gameObject); }
public override void Update(Groundy groundy) { }
public abstract void EnterState(Groundy groundy);
void Setup(Groundy groundy) { }
public override void EnterState(Groundy groundy) { groundy.animator.Play("Walking"); }
public Vector2 CalculateDirection(Groundy groundy) { return((groundy.moreFrontTransform.position - groundy.frontTransform.position).normalized); }