public void Equip() { playerController = GetComponentInParent <PlayerController>(); //playerController.PickUpGun(); playerUIManager = playerController.GetUIManager(); playerUIManager.ChangeGunAmmoUI(clipAmmo, maxClipAmmo); playerUIManager.ChangeGunUI(gunName); }
//[ClientRpc] public void Fire(Camera playerCamera) { if (!canFire) { return; } shotLine.SetPosition(0, gameObject.transform.position); Vector3 rayOrigin = playerCamera.ViewportToWorldPoint(new Vector3(.5f, .5f, 0)); RaycastHit hit; if (Physics.Raycast(rayOrigin, playerCamera.transform.forward, out hit, maxRange, 3)) { shotLine.SetPosition(1, hit.point); GameObject hitGameObject = hit.collider.gameObject; if (hitGameObject.GetComponent <Health>()) { int damage = CalculateDamage(hit.distance); hitGameObject.GetComponent <Health>().TakeDamage(damage); } } else { shotLine.SetPosition(1, rayOrigin + (playerCamera.transform.forward * maxRange)); } StartCoroutine(ShowShot()); canFire = false; clipAmmo--; playerUIManager.ChangeGunAmmoUI(clipAmmo, maxClipAmmo); if (clipAmmo <= 0) { StartCoroutine(ReloadCo()); } else { StartCoroutine(WaitToFire(1 / fireRate)); } }
void Start() { shotLine = GetComponent <LineRenderer>(); playerController = GetComponentInParent <PlayerController>(); if (playerController != null) { playerUIManager = playerController.GetUIManager(); playerUIManager.ChangeGunAmmoUI(maxClipAmmo, maxClipAmmo); } gi = GetComponent <GunInteractable>(); canFire = true; reloading = false; clipAmmo = maxClipAmmo; }