public void moveUnit(Vector3 hit) { if (OUT == false) { //MOVE OUR AGENT //defenseNorth = defenseEast = defenseSouth = defenseWest = 0; anim.SetBool("isRunning", true); agent.SetDestination(hit); actionCount -= inRange; isMoving = true; gameManager.teamActionCount -= inRange; gameManager.SetActionText(); audioSource.PlayOneShot(footsteps, 0.7f); } }
// Update is called once per frame void Update() { if (rb.velocity.magnitude > 0) { isMoving = true; } if (gameManager.playerTurn) { if (Input.GetMouseButtonDown(0)) { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { if (hit.transform.gameObject == gameObject && OUT == false) { PlayerController currentHero = gameManager.CheckActiveHero(); if (currentHero.OUT == false) { //currentHero.actionCount--; gameManager.teamActionCount--; gameManager.SetActionText(); GameObject clone = Instantiate(bullet, currentHero.transform.position, currentHero.transform.rotation); clone.GetComponent <BulletScript>().target = gameObject; int currentDefense = gameManager.calculateDefense(currentHero.gameObject, gameObject); hp -= (currentHero.attack - currentDefense); UpdateUI(); if (hp <= 0) { gameManager.falseEnemyCount--; gameManager.enemyCountText.text = "Enemy Count: " + gameManager.falseEnemyCount.ToString(); //gameObject.SetActive(false); anim.SetBool("isOut", true); Debug.Log("Enemy OUT! Nice shot!"); healthText.text = "KO!"; OUT = true; } } } } } } if (agent.remainingDistance <= 0.1 && isMoving) { isMoving = false; audioSource.Stop(); RaycastHit hit; Physics.Raycast(transform.position, -Vector3.up, out hit); Debug.Log(hit.collider.gameObject); Tile currentTile = hit.transform.gameObject.GetComponent <Tile>(); defenseNorth = currentTile.northCover; defenseSouth = currentTile.southCover; defenseEast = currentTile.eastCover; defenseWest = currentTile.westCover; anim.SetBool("isRunning", false); if (defenseNorth + defenseSouth + defenseEast + defenseWest > 0) { anim.SetBool("isCrouching", true); } else { anim.SetBool("isCrouching", false); } } }