void BeIdle() { if (timer > 2) { MyState = MinerStates.PATROL; } }
private void HandleMovement() { if (pathVectorList != null) { Vector3 targetPosition = pathVectorList[currentPathIndex]; if (Vector3.Distance(transform.position, targetPosition) > 1f) { Vector3 moveDir = (targetPosition - transform.position).normalized; float distanceBefore = Vector3.Distance(transform.position, targetPosition); transform.position = transform.position + moveDir * speed * Time.deltaTime; } else { currentPathIndex++; if (currentPathIndex >= pathVectorList.Count) { StopMoving(); hasObjective = false; if (MyState == MinerStates.PATROL) { MyState = MinerStates.IDLE; } } } } }
private void OnTriggerEnter2D(Collider2D col) { if (col.gameObject.tag == "Mine") { if (MyState == MinerStates.PATROL) { targetMine = col.gameObject; StopMoving(); hasObjective = false; MyState = MinerStates.MINING; } } }
private void Returning() { PathFinding.Instance.GetGrid().GetXY(new Vector3(homeBase.transform.position.x, homeBase.transform.position.y, 5), out int x, out int y); this.SetTargetPosition(PathFinding.Instance.GetGrid().GetWorldPosition(x, y)); hasObjective = true; HandleMovement(); if (!hasObjective) { GameManager.Instance.AddGold(goldCapacity); goldCapacity = 0; if (targetMine != null) { MyState = MinerStates.MINING; } else { MyState = MinerStates.IDLE; } } }
private void Mining() { if (targetMine != null) { PathFinding.Instance.GetGrid().GetXY(new Vector3(targetMine.transform.position.x, targetMine.transform.position.y, 5), out int x, out int y); this.SetTargetPosition(PathFinding.Instance.GetGrid().GetWorldPosition(x, y)); hasObjective = true; HandleMovement(); } else { MyState = MinerStates.RETURNING; } if (!hasObjective && targetMine != null) { goldCapacity = goldCapacity + 5 * Time.deltaTime; targetMine.GetComponent <GoldMine>().LoseGold(goldCapacity); } if (goldCapacity >= 10) { MyState = MinerStates.RETURNING; } }
private void Start() { MyState = MinerStates.IDLE; }