void CommandSelection() { if (Input.GetMouseButtonDown(1)) { if (selectedUnit != null) { GameManager.instance.audioSource.PlayOneShot(GameManager.instance.selection); selectedUnit.tryToBoard = false; selectedUnit.buildingToTryToEnter = null; if (commandIndicator.mode == CommandType.BOARD) { commandPosition = DockZone.zoneForLocation[Island.AtPoint(selectedUnit.transform.position).location].GetRandomPoint(); selectedUnit.tryToBoard = true; } else if (commandIndicator.mode == CommandType.ENTER) { selectedUnit.buildingToTryToEnter = buildingUnderCursor; } selectedUnit.MoveTo(commandPosition); IntroManager.instance.OnMoveCommandSent(); } } }
private void Update() { if (animating) { return; } if (currentHealth <= 0) { GameManager.instance.deathsSoFar++; GameManager.instance.audioSource.PlayOneShot(GameManager.instance.playerDead); Instantiate(deathParticle.gameObject).transform.position = transform.position; Destroy(gameObject); return; } if (isCivilian) { if (Island.AtPoint(transform.position).location == Boat.Location.Freedom) { if (agent.enabled) { GameManager.instance.audioSource.PlayOneShot(GameManager.instance.alright); } agent.enabled = false; transform.Translate(Vector2.right * Time.deltaTime * agent.movementSpeed * 2); } if (transform.position.x >= 9) { Destroy(gameObject); GameManager.instance.rescued++; } } else { UpdateTarget(); cooldownRemaining = Mathf.Max(0, attackCooldown - (Time.time - lastAttackTime)); if (targetZombie != null && cooldownRemaining == 0) { DoAttack(); } } if (currentBuilding != null) { transform.position = currentBuilding.roofSpot.position; } if (tryToBoard && !agent.isMoving) { // Check if we are at a boarding location var dockZone = Physics2D.OverlapPointAll(transform.position).FirstOrDefault(x => x.GetComponentInParent <DockZone>() != null); if (dockZone != null) { var currentLocation = dockZone.GetComponent <DockZone>().location; if (Boat.instance.isDocked && Boat.instance.currentLocation == currentLocation) { if (!Boat.instance.TryLoad(this)) { tryToBoard = false; } } } } if (currentBuilding == null && buildingToTryToEnter != null && !agent.isMoving) { var buildingToEnter = Physics2D.OverlapPointAll(transform.position).FirstOrDefault(x => x.GetComponentInParent <BuildingController>() == buildingToTryToEnter); if (buildingToEnter && buildingToTryToEnter.unitOnRoof == null) { StartCoroutine(EnterBuilding(buildingToTryToEnter)); } } }