Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Photon.Pun;
- public class BuckShot : Gun
- {
- [SerializeField] Camera cam;
- PhotonView PV;
- List<Ray> shotRays = new List<Ray>();
- [SerializeField] Transform gunBarrel;
- private void Awake()
- {
- baseDamage = gunInfo.damage;
- PV = GetComponent<PhotonView>();
- ammoCount = maxAmmo;
- ammoCounter.text = ammoCounter.text + ammoCount.ToString();
- }
- public override void Use()
- {
- if (Time.time < lastShot + timeBetweenShots)
- return;
- if (ammoCount > 0)
- {
- Shoot();
- lastShot = Time.time;
- ammoCount--;
- ammoCounter.text = ammoCount.ToString();
- }
- if (ammoCount <= 0)
- {
- ammoCount = 0;
- ammoCounter.text = ammoCount.ToString();
- }
- }
- public override void Reload()
- {
- ammoCount = maxAmmo;
- ammoCounter.text = ammoCount.ToString();
- }
- void Shoot()
- {
- for (int i = 0; i < shotsPerAttack; i++)
- {
- Ray ray = cam.ViewportPointToRay(GetOverallSpread() + new Vector2(0.5f,0.5f));
- ray.origin = cam.transform.position;
- shotRays.Add(ray);
- }
- foreach (Ray ray in shotRays)
- {
- if (Physics.Raycast(ray, out RaycastHit hit))
- {
- hit.collider.gameObject.GetComponent<IDamageable>()?.TakeDamage(((GunInfo)itemInfo).damage);
- PV.RPC("RPC_Shoot", RpcTarget.All, hit.point, hit.normal); //this will run on all in game clients
- }
- }
- //Ray ray = cam.ViewportPointToRay(new Vector3(0.5f, 0.5f));
- //ray.origin = cam.transform.position;
- //if (Physics.Raycast(ray, out RaycastHit hit))
- //{
- //hit.collider.gameObject.GetComponent<IDamageable>()?.TakeDamage(((GunInfo)itemInfo).damage);
- //PV.RPC("RPC_Shoot", RpcTarget.All, hit.point, hit.normal); //this will run on all in game clients
- //}
- }
- Vector2 GetIndividualSpread()
- {
- return Random.insideUnitCircle * individualSpread;
- }
- Vector2 GetOverallSpread()
- {
- return Random.insideUnitCircle * overallSpread;
- }
- [PunRPC]
- void RPC_Shoot(Vector3 hitPos, Vector3 hitNormal)
- {
- Collider[] colliders = Physics.OverlapSphere(hitPos, 0.3f);
- if (colliders.Length != 0)
- {
- GameObject bulletImpactObj = Instantiate(bulletImpactPrefab, hitPos + hitNormal * 0.001f, Quaternion.LookRotation(hitNormal, Vector3.up) * bulletImpactPrefab.transform.rotation); //instantiate a bullet impact prefab on the obj hit facing towards the player
- Destroy(bulletImpactObj, 5.0f);
- bulletImpactObj.transform.SetParent(colliders[0].transform); //parents the instantiated bulletimpact Obj
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement