- Im making small Fps Multiplayer Game using Unity 3d and Photon. I added Recoil system to my game, it works fine for the first player, after another player spawn Recoil System not working for the first player and working for the second player.
Im new to unity btw
Here is my Code
I callout
RecoilFire()in shooting scriptRecoil.cs
using UnityEngine; using Photon.Pun; public class Recoil : MonoBehaviourPunCallbacks { //Scripts [SerializeField] private AimScript Player_Scripts_aim ; private bool isAiming; //Rotation private Vector3 currentRotation; private Vector3 targetRotation; //ADS Recoil [SerializeField] private float recoilX; [SerializeField] private float recoilY; [SerializeField] private float recoilZ; //ADS Recoil [SerializeField] private float aimRecoilX; [SerializeField] private float aimRecoilY; [SerializeField] private float aimRecoilZ; //Settings [SerializeField] private float snapiness; [SerializeField] private float returnSpeed; void Start() { } void Update() { isAiming = Player_Scripts_aim.aiming; targetRotation = Vector3.Lerp(targetRotation, Vector3.zero, returnSpeed * Time.deltaTime); currentRotation = Vector3.Slerp(currentRotation, targetRotation, snapiness * Time.fixedDeltaTime); transform.localRotation = Quaternion.Euler(currentRotation); } public void RecoilFire() { if (gameObject.transform.localEulerAngles.x >= 330 || gameObject.transform.localEulerAngles.x <= 0)//make return speed higher as it goes higher { if (isAiming) targetRotation += new Vector3(aimRecoilX, Random.Range(-aimRecoilY, aimRecoilY), Random.Range(-aimRecoilZ, aimRecoilZ)); else targetRotation += new Vector3(recoilX, Random.Range(-recoilY, recoilY), Random.Range(-recoilZ, recoilZ)); Debug.Log("REcoil script running"); } }}
When I debug I noticed Variables Value changes as well (It means code is running not the Movement of gun)
Sorry for bad English and I'm stuck with this bug for long days