private bool SearchForPath() { bool rtn = false; status = AI.Status.wander; if (hunger > searchForFoodHunger) { FindFood(); } switch (status) { case AI.Status.eat: SetFlip(((targetFood.position - transform.position).normalized).x); animator.SetTrigger("Eat"); break; case AI.Status.chase: moveDirection = (targetFood.position - transform.position).normalized; rtn = true; break; case AI.Status.wander: moveDirection = Random.insideUnitCircle; rtn = true; break; default: break; } return(rtn); }
// Update is called once per frame void Update() { //jumping if (isJump) { cell.position = new Vector2(cell.position.x, cell.position.y + velocity.y); height += velocity.y; velocity.y -= gravity * Time.deltaTime; UpdateShadow(); Move(); if (cell.position.y <= transform.position.y) { cell.position = transform.position; height = 0.0f; velocity.y = 0f; isJump = false; ResetShadow(); StartCoroutine(NextAction(moveInterval)); StartCoroutine(JumpAfterEffect(moveInterval / 20f)); } } // hunger hunger = Mathf.Clamp(hunger + (hungerIncreaseRate * Time.deltaTime), 0.0f, 2.0f); if (hunger >= 1.0f && status != AI.Status.dead) { cell.transform.position -= shake; shake.x = Random.Range(-shakeMagnitude, shakeMagnitude); shake.y = Random.Range(-shakeMagnitude, shakeMagnitude); cell.transform.position += shake; if (StarveToDeath()) { animator.SetTrigger("Death"); status = AI.Status.dead; spirit = Instantiate(spirit, transform); } else { Debug.Log("survived!"); } } else if (status == AI.Status.dead) { DrawSpirit(); } //Rescale ResizeCell(); //animator animator.SetFloat("Hunger", hunger); }
// Start is called before the first frame update void Start() { shadow = transform.GetChild(0); cell = transform.GetChild(1); originalColor = cell.GetComponent <SpriteRenderer>().color; cellRenderer = cell.GetComponent <SpriteRenderer>(); originalShadowScale = shadow.localScale; originalCellScale = cell.localScale; shadowRenderer = shadow.GetComponent <SpriteRenderer>(); animator = GetComponentInChildren <Animator>(); isJump = false; bounceFlag = true; hunger = 0.0f; status = AI.Status.wander; StartCoroutine(NextAction(moveInterval)); }
private void FindFood() { if (CurrentScene.Instance().GetRegisteredFoodNumber() > 0) { targetFood = CurrentScene.Instance().GetNearestFood(transform.position); Vector2 targetPos = targetFood.position; if (cell.GetComponent <Collider2D>().ClosestPoint(targetPos) == targetPos) { status = AI.Status.eat; } else { status = AI.Status.chase; } } else { status = AI.Status.wander; } }