Quantcast
Channel: Questions in topic: "gun"
Viewing all articles
Browse latest Browse all 592

How to make delay for shooting in Unity/photon 2

$
0
0
Here is my code: using Photon.Pun; using System.Collections; using System.Collections.Generic; using UnityEngine; public class SingleShotGun : Gun { [SerializeField] Camera cam; PhotonView PV; public AudioSource m_shootingsound; public GameObject bloodEffect; float timeBetweenShots = 2; void Start() { m_shootingsound = GetComponent(); } void Awake() { PV = GetComponent(); } public override void Use() { Shoot(); } void Shoot() { Ray ray = cam.ViewportPointToRay(new Vector3(0.5f, 0.5f)); ray.origin = cam.transform.position; if (Physics.Raycast(ray, out RaycastHit hit)) { m_shootingsound.Play(); Debug.Log("Pow!"); hit.collider.gameObject.GetComponent()?.TakeDamage(((GunInfo)itemInfo).damage); PV.RPC("RPC_Shoot", RpcTarget.All, hit.point, hit.normal); if (hit.transform.tag == "Player") { Instantiate(bloodEffect, hit.point, Quaternion.identity); } } } [PunRPC] void RPC_Shoot(Vector3 hitPosition, Vector3 hitNormal) { Collider[] colliders = Physics.OverlapSphere(hitPosition, 0.3f); if (colliders.Length != 0) { GameObject bulletImpactObj = Instantiate(bulletImpactPrefab, hitPosition + hitNormal * 0.001f, Quaternion.LookRotation(hitNormal, Vector3.up) * bulletImpactPrefab.transform.rotation); Destroy(bulletImpactObj, 10f); bulletImpactObj.transform.SetParent(colliders[0].transform); } } }

Viewing all articles
Browse latest Browse all 592

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>