// Update is called once per frame void Update() { CheckIfNearCover(); if (Input.GetMouseButton(0)) { shootingTime += Time.deltaTime; if (ammo > 0 && reloading == false && shooting == false) { if (accuracy - (shootingTime / 2) > 5) { accuracy -= (shootingTime / 2); } else { accuracy = 5; } StartCoroutine(Shoot()); Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (hit.collider != null) { GameObject hitObject = hit.collider.gameObject; if (hitObject.CompareTag("Enemy")) { StartCoroutine(AttackingAgent(hitObject.gameObject)); AgentScript agentScript = hitObject.GetComponent <AgentScript>(); if (agentScript == null) { return; } int random = Random.Range(0, 101); if (random <= accuracy) { agentScript.ReceiveDamage(damage); } } else if (hitObject.CompareTag("Big Object") || hitObject.CompareTag("Small Object")) { //if(attackedCover != hitObject.gameObject) //{ StartCoroutine(AttackingCover(hitObject.gameObject)); //} } } } } } else { shootingTime = 0.0f; accuracy = 30; } if (Input.GetKeyDown(KeyCode.R)) { UnityEngine.Debug.Log("R pressed, ammo " + ammo + " reloading " + reloading); if (reloading == false && ammo < clipAmount) { StartCoroutine(Reload()); } } if (Input.GetKeyDown(KeyCode.LeftControl)) { if (crouching) { crouching = false; gameObject.transform.localScale = new Vector3(2.77f, 4.22f, 3.06f); } else { crouching = true; gameObject.transform.localScale = new Vector3(2.77f, 3.0f, 3.06f); } } }