Search Unity

Third Party Photon sync problem

Discussion in 'Multiplayer' started by FedeStefan, Mar 28, 2020.

  1. FedeStefan

    FedeStefan

    Joined:
    Aug 15, 2018
    Posts:
    221
    hello to anybody reading this.
    i have 2 problems with syncing.
    player model sync animation and weapon sync.
    so let me explain.
    some how the player model sync animation stopped working (when i fixed it) but the legs (cause i use the same animation but its only for local player to see their legs) still works. (with this i mean, multiplayer model animation doesnt sync, only idle animation plays and thats all, mean while singleplayer model animation still doesnt work)
    and the weapon sync, it just only has 1 gun model but tho it should change, when i have a rpg it should show that i have the rpg but it doesnt)
    heres my scripts
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5. public class CharacterAnimation : MonoBehaviour
    6. {
    7.     [HideInInspector]
    8.     public string animationSyncHelper;
    9.     [HideInInspector]
    10.     public string animationForHands;
    11.     [HideInInspector]
    12.     public string activeWeapon;
    13.     [HideInInspector]
    14.     public string animationType;
    15.  
    16.     public WeaponManager weaponManager;
    17.     public enum Action { Stand, Crouch, Prone }
    18.     Action action;
    19.     [System.Serializable]
    20.     public class animations
    21.     {
    22.         public AnimationClip jumpPose;
    23.         public AnimationClip stayIdle;
    24.         public AnimationClip crouchIdle;
    25.         public AnimationClip proneIdle;
    26.         public AnimationClip walkFront;
    27.         public AnimationClip runFront;
    28.         public AnimationClip crouchFront;
    29.         public AnimationClip proneFront;
    30.         public AnimationClip pistolIdle;
    31.         public AnimationClip knifeIdle;
    32.         public AnimationClip gunIdle;
    33.     }
    34.  
    35.     public animations Animations;
    36.     public List<WeaponScript> twoHandedWeapons = new List<WeaponScript>();
    37.     public List<WeaponScript> pistols = new List<WeaponScript>();
    38.     public List<WeaponScript> knivesNades = new List<WeaponScript>();
    39.     FPScontroller fpsController;
    40.  
    41.     void Start()
    42.     {
    43.         fpsController = transform.root.GetComponent<FPScontroller>();
    44.         configureAnimations();
    45.         if (weaponManager)
    46.         {
    47.             ThirdPersonWeaponControl();
    48.         }
    49.     }
    50.  
    51.     void LateUpdate()
    52.     {
    53.         if (weaponManager.SelectedWeapon)
    54.         {
    55.             activeWeapon = weaponManager.SelectedWeapon.weaponName;
    56.         }
    57.         if (!fpsController.crouch && !fpsController.prone)
    58.         {
    59.             action = Action.Stand;
    60.         }
    61.         else
    62.         {
    63.             if (fpsController.crouch && !fpsController.prone)
    64.             {
    65.                 action = Action.Crouch;
    66.             }
    67.             if (!fpsController.crouch && fpsController.prone)
    68.             {
    69.                 action = Action.Prone;
    70.             }
    71.             if (fpsController.crouch && fpsController.prone)
    72.             {
    73.                 action = Action.Crouch;
    74.             }
    75.         }
    76.  
    77.         if (action == Action.Stand)
    78.         {
    79.             if (fpsController.grounded)
    80.             {
    81.                 if (fpsController.Walking)
    82.                 {
    83.                     if (!fpsController.Running)
    84.                     {
    85.                         animationType = "Walking";
    86.                         if (Input.GetKey(KeyCode.W))
    87.                         {
    88.                             GetComponent<Animation>().CrossFade(Animations.walkFront.name, 0.2f);
    89.                             animationSyncHelper = Animations.walkFront.name;
    90.                         }
    91.                         else if (Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.S))
    92.                         {
    93.                             GetComponent<Animation>().CrossFade(Animations.walkFront.name, 0.2f);
    94.                             animationSyncHelper = Animations.walkFront.name;
    95.                         }
    96.                         else if (Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.S))
    97.                         {
    98.                             GetComponent<Animation>().CrossFade(Animations.walkFront.name, 0.2f);
    99.                             animationSyncHelper = Animations.walkFront.name;
    100.                         }
    101.                         else if (Input.GetKey(KeyCode.S))
    102.                         {
    103.                             GetComponent<Animation>().CrossFade(Animations.walkFront.name, 0.2f);
    104.                             animationSyncHelper = Animations.walkFront.name;
    105.                         }
    106.                     }
    107.                     else
    108.                     {
    109.                         animationType = "Running";
    110.                         if (Input.GetKey(KeyCode.W))
    111.                         {
    112.                             GetComponent<Animation>().CrossFade(Animations.runFront.name, 0.2f);
    113.                             animationSyncHelper = Animations.runFront.name;
    114.                         }
    115.                     }
    116.                 }
    117.                 else
    118.                 {
    119.                     GetComponent<Animation>().CrossFade(Animations.stayIdle.name, 0.2f);
    120.                     animationSyncHelper = Animations.stayIdle.name;
    121.                 }
    122.             }
    123.             else
    124.             {
    125.                 GetComponent<Animation>().CrossFade(Animations.jumpPose.name, 0.2f);
    126.                 animationSyncHelper = Animations.jumpPose.name;
    127.             }
    128.         }
    129.  
    130.         if (action == Action.Crouch)
    131.         {
    132.             animationType = "Crouch";
    133.             if (fpsController.Walking)
    134.             {
    135.                 if (Input.GetKey(KeyCode.W))
    136.                 {
    137.                     GetComponent<Animation>().CrossFade(Animations.crouchFront.name, 0.2f);
    138.                     animationSyncHelper = Animations.crouchFront.name;
    139.                 }
    140.                 else if (Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.S))
    141.                 {
    142.                     GetComponent<Animation>().CrossFade(Animations.crouchFront.name, 0.2f);
    143.                     animationSyncHelper = Animations.crouchFront.name;
    144.                 }
    145.                 else if (Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.S))
    146.                 {
    147.                     GetComponent<Animation>().CrossFade(Animations.crouchFront.name, 0.2f);
    148.                     animationSyncHelper = Animations.crouchFront.name;
    149.                 }
    150.                 else if (Input.GetKey(KeyCode.S))
    151.                 {
    152.                     GetComponent<Animation>().CrossFade(Animations.crouchFront.name, 0.2f);
    153.                     animationSyncHelper = Animations.crouchFront.name;
    154.                 }
    155.             }
    156.             else
    157.             {
    158.                 GetComponent<Animation>().CrossFade(Animations.crouchIdle.name, 0.2f);
    159.                 animationSyncHelper = Animations.crouchIdle.name;
    160.             }
    161.         }
    162.         if (action == Action.Prone)
    163.         {
    164.             animationType = "Prone";
    165.             if (fpsController.Walking)
    166.             {
    167.                 if (Input.GetKey(KeyCode.W))
    168.                 {
    169.                     GetComponent<Animation>().CrossFade(Animations.proneFront.name, 0.2f);
    170.                     animationSyncHelper = Animations.proneFront.name;
    171.                 }
    172.                 else if (Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.S))
    173.                 {
    174.                     GetComponent<Animation>().CrossFade(Animations.proneFront.name, 0.2f);
    175.                     animationSyncHelper = Animations.proneFront.name;
    176.                 }
    177.                 else if (Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.S))
    178.                 {
    179.                     GetComponent<Animation>().CrossFade(Animations.proneFront.name, 0.2f);
    180.                     animationSyncHelper = Animations.proneFront.name;
    181.                 }
    182.                 else if (Input.GetKey(KeyCode.S))
    183.                 {
    184.                     GetComponent<Animation>().CrossFade(Animations.proneFront.name, 0.2f);
    185.                     animationSyncHelper = Animations.proneFront.name;
    186.                 }
    187.             }
    188.             else
    189.             {
    190.                 GetComponent<Animation>().CrossFade(Animations.proneIdle.name, 0.2f);
    191.                 animationSyncHelper = Animations.proneIdle.name;
    192.             }
    193.         }
    194.         ThirdPersonWeaponControl();
    195.     }
    196.  
    197.     void ThirdPersonWeaponControl()
    198.     {
    199.         if (action != Action.Prone)
    200.         {
    201.             if (twoHandedWeapons.Contains(weaponManager.SelectedWeapon))
    202.             {
    203.                 animationForHands = Animations.gunIdle.name;
    204.             }
    205.             else if (pistols.Contains(weaponManager.SelectedWeapon))
    206.             {
    207.                 animationForHands = Animations.pistolIdle.name;
    208.             }
    209.             else if (knivesNades.Contains(weaponManager.SelectedWeapon))
    210.             {
    211.                 animationForHands = Animations.knifeIdle.name;
    212.             }
    213.         }
    214.         else
    215.         {
    216.             animationForHands = "Null";
    217.         }
    218.     }
    219.  
    220.     void configureAnimations()
    221.     {
    222.         if (Animations.stayIdle)
    223.         {
    224.             GetComponent<Animation>()[Animations.stayIdle.name].wrapMode = WrapMode.Loop;
    225.         }
    226.         if (Animations.crouchIdle)
    227.         {
    228.             GetComponent<Animation>()[Animations.crouchIdle.name].wrapMode = WrapMode.Loop;
    229.         }
    230.         if (Animations.proneIdle)
    231.         {
    232.             GetComponent<Animation>()[Animations.proneIdle.name].wrapMode = WrapMode.Loop;
    233.         }
    234.         if (Animations.walkFront)
    235.         {
    236.             GetComponent<Animation>()[Animations.walkFront.name].wrapMode = WrapMode.Loop;
    237.         }
    238.         if (Animations.runFront)
    239.         {
    240.             GetComponent<Animation>()[Animations.runFront.name].wrapMode = WrapMode.Loop;
    241.         }
    242.         if (Animations.crouchFront)
    243.         {
    244.             GetComponent<Animation>()[Animations.crouchFront.name].wrapMode = WrapMode.Loop;
    245.         }
    246.         if (Animations.proneFront)
    247.         {
    248.             GetComponent<Animation>()[Animations.proneFront.name].wrapMode = WrapMode.Loop;
    249.         }
    250.     }
    251. }
    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine;
    3.  
    4. [RequireComponent(typeof(AudioSource))]
    5. public class WeaponSync : MonoBehaviour
    6. {
    7.     public WeaponScript firstPersonWeapon;
    8.     public Transform firePoint;
    9.     public GameObject bullet;
    10.     public Renderer muzzleFlash;
    11.     public Rigidbody projectile;
    12.     public AudioClip fireAudio;
    13.     private void Start()
    14.     {
    15.         if ((bool)muzzleFlash)
    16.         {
    17.             muzzleFlash.GetComponent<Renderer>().enabled = false;
    18.         }
    19.         GetComponent<AudioSource>().playOnAwake = false;
    20.         GetComponent<AudioSource>().volume = 0.5f;
    21.         if (GetComponent<AudioSource>().maxDistance > 10f)
    22.         {
    23.             GetComponent<AudioSource>().maxDistance = 75f;
    24.             GetComponent<AudioSource>().minDistance = 0f;
    25.         }
    26.         if (!firstPersonWeapon)
    27.         {
    28.             return;
    29.         }
    30.         if (firstPersonWeapon.GunType == WeaponScript.gunType.MACHINE_GUN)
    31.         {
    32.             if ((bool)firstPersonWeapon.machineGun.bullet)
    33.             {
    34.                 bullet = firstPersonWeapon.machineGun.bullet.gameObject;
    35.             }
    36.             if ((bool)firstPersonWeapon.machineGun.fireSound)
    37.             {
    38.                 fireAudio = firstPersonWeapon.machineGun.fireSound;
    39.             }
    40.         }
    41.         if (firstPersonWeapon.GunType == WeaponScript.gunType.SHOTGUN)
    42.         {
    43.             if ((bool)firstPersonWeapon.ShotGun.bullet)
    44.             {
    45.                 bullet = firstPersonWeapon.ShotGun.bullet.gameObject;
    46.             }
    47.             if ((bool)firstPersonWeapon.ShotGun.fireSound)
    48.             {
    49.                 fireAudio = firstPersonWeapon.ShotGun.fireSound;
    50.             }
    51.         }
    52.         if (firstPersonWeapon.GunType == WeaponScript.gunType.GRENADE_LAUNCHER)
    53.         {
    54.             if ((bool)firstPersonWeapon.grenadeLauncher.projectile)
    55.             {
    56.                 projectile = firstPersonWeapon.grenadeLauncher.projectile;
    57.             }
    58.             if ((bool)firstPersonWeapon.grenadeLauncher.fireSound)
    59.             {
    60.                 fireAudio = firstPersonWeapon.grenadeLauncher.fireSound;
    61.             }
    62.         }
    63.         if (firstPersonWeapon.GunType == WeaponScript.gunType.KNIFE && (bool)firstPersonWeapon.knife.fireSound)
    64.         {
    65.             fireAudio = firstPersonWeapon.knife.fireSound;
    66.         }
    67.     }
    68.  
    69.     private void syncMachineGun(float errorAngle)
    70.     {
    71.         StopAllCoroutines();
    72.         StartCoroutine(machineGunShot(errorAngle));
    73.     }
    74.  
    75.     private IEnumerator machineGunShot(float errorAngle)
    76.     {
    77.         Quaternion oldRotation = firePoint.rotation;
    78.         firePoint.rotation = Quaternion.Euler(UnityEngine.Random.insideUnitSphere * errorAngle) * firePoint.rotation;
    79.         GameObject instantiatedBullet = UnityEngine.Object.Instantiate(bullet, firePoint.position, firePoint.rotation);
    80.         instantiatedBullet.GetComponent<Bullet>().doDamage = false;
    81.         firePoint.rotation = oldRotation;
    82.         GetComponent<AudioSource>().clip = fireAudio;
    83.         GetComponent<AudioSource>().Play();
    84.         if ((bool)muzzleFlash)
    85.         {
    86.             muzzleFlash.GetComponent<Renderer>().enabled = true;
    87.             yield return new WaitForSeconds(0.04f);
    88.             muzzleFlash.GetComponent<Renderer>().enabled = false;
    89.         }
    90.     }
    91.  
    92.     private void syncShotGun(float fractions)
    93.     {
    94.         StopAllCoroutines();
    95.         StartCoroutine(shotGunShot(fractions));
    96.     }
    97.  
    98.     private IEnumerator shotGunShot(float fractions)
    99.     {
    100.         for (int i = 0; i < (int)fractions; i++)
    101.         {
    102.             Quaternion rotation = firePoint.rotation;
    103.             firePoint.rotation = Quaternion.Euler(UnityEngine.Random.insideUnitSphere * 3f) * firePoint.rotation;
    104.             GameObject gameObject = UnityEngine.Object.Instantiate(bullet, firePoint.position, firePoint.rotation);
    105.             gameObject.GetComponent<Bullet>().doDamage = false;
    106.             firePoint.rotation = rotation;
    107.         }
    108.         GetComponent<AudioSource>().clip = fireAudio;
    109.         GetComponent<AudioSource>().Play();
    110.         if ((bool)muzzleFlash)
    111.         {
    112.             muzzleFlash.GetComponent<Renderer>().enabled = true;
    113.             yield return new WaitForSeconds(0.04f);
    114.             muzzleFlash.GetComponent<Renderer>().enabled = false;
    115.         }
    116.     }
    117.  
    118.     private void syncGrenadeLauncher(float initialSpeed)
    119.     {
    120.         grenadeLauncherShot(initialSpeed);
    121.     }
    122.  
    123.     private void grenadeLauncherShot(float initialSpeed)
    124.     {
    125.         Rigidbody rigidbody = UnityEngine.Object.Instantiate(projectile, firePoint.position, firePoint.rotation);
    126.         rigidbody.GetComponent<Projectile>().isRemote = true;
    127.         rigidbody.AddForce(rigidbody.transform.forward * initialSpeed * 50f);
    128.         Physics.IgnoreCollision(rigidbody.GetComponent<Collider>(), base.transform.root.GetComponent<Collider>());
    129.         Collider[] componentsInChildren = base.transform.root.GetComponentsInChildren<Collider>();
    130.         foreach (Collider collider in componentsInChildren)
    131.         {
    132.             Physics.IgnoreCollision(rigidbody.GetComponent<Collider>(), collider);
    133.         }
    134.         GetComponent<AudioSource>().clip = fireAudio;
    135.         GetComponent<AudioSource>().Play();
    136.     }
    137.  
    138.     private void syncKnife(float temp)
    139.     {
    140.         knifeOneHit();
    141.     }
    142.  
    143.     private void knifeOneHit()
    144.     {
    145.         GetComponent<AudioSource>().clip = fireAudio;
    146.         GetComponent<AudioSource>().Play();
    147.     }
    148. }
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class WeaponSync_Catcher : MonoBehaviour
    4. {
    5.     private Transform playerRoot;
    6.     private WeaponScript weapScript;
    7.     private PlayerNetworkController pnc;
    8.  
    9.     private void Awake()
    10.     {
    11.         weapScript = base.gameObject.GetComponent<WeaponScript>();
    12.         playerRoot = base.transform.root;
    13.         pnc = playerRoot.GetComponent<PlayerNetworkController>();
    14.     }
    15.  
    16.     public void Fire()
    17.     {
    18.         if (weapScript.GunType == WeaponScript.gunType.MACHINE_GUN)
    19.         {
    20.             pnc.syncMachineGun(weapScript.errorAngle);
    21.         }
    22.         if (weapScript.GunType == WeaponScript.gunType.SHOTGUN)
    23.         {
    24.             pnc.syncShotGun(weapScript.ShotGun.fractions);
    25.         }
    26.         if (weapScript.GunType == WeaponScript.gunType.GRENADE_LAUNCHER)
    27.         {
    28.             pnc.syncGrenadeLauncher(weapScript.grenadeLauncher.initialSpeed);
    29.         }
    30.         if (weapScript.GunType == WeaponScript.gunType.KNIFE)
    31.         {
    32.             pnc.syncKnife();
    33.         }
    34.     }
    35. }
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. public class PlayerNetworkController : Photon.MonoBehaviour {
    5.     [HideInInspector]
    6.     public string playerName;
    7.     public Transform lookTarget;
    8.     CharacterController cc;
    9.     RoomMultiplayerMenu rmm;
    10.     GameObject currentActiveWeapon;
    11.     public Transform thirdPersonWeapons;
    12.     public Transform shoulderR;
    13.     public Transform shoulderL;
    14.     public CharacterAnimation characterAnimation;
    15.     [System.Serializable]
    16.     public class AnimationSpeed{
    17.         public float walkSpeed = 1;
    18.         public float runSpeed = 1;
    19.         public float crouchSpeed = 1;
    20.         public float proneSpeed = 1;
    21.     }
    22.     public AnimationSpeed animationSpeed;
    23.     List<string> mixedAnimations = new List<string>();
    24.     string MovementAnimation;
    25.     string currentBlendedAnimation;
    26.     string currentWeaponName;    
    27.     private string currentAnimation = "";
    28.     private string blendedAnimation = "";
    29.     private string prevWeap = "";
    30.     public DrawPlayerName drawPlayerName;
    31.     public PlayerDamage playerDamage;
    32.     public HeadLookController headLookController;
    33.     public List<GameObject> remoteObjectsToDeactivate;
    34.     public List<MonoBehaviour> remoteScriptsToDeactivate;
    35.     public List<GameObject> localObjectsToDeactivate;
    36.     public List<MonoBehaviour> localScriptsToDeactivate;
    37.     [HideInInspector]
    38.     public bool playerIsOurs;
    39.     void Awake () {
    40.         if(!photonView.isMine){
    41.             for(int i = 0; i<remoteObjectsToDeactivate.Count;i++){
    42.                 remoteObjectsToDeactivate[i].SetActive(false);  
    43.             }
    44.             for(int a = 0; a<remoteScriptsToDeactivate.Count;a++){
    45.                 Destroy(remoteScriptsToDeactivate[a]);
    46.             }
    47.             gameObject.tag = "Remote";
    48.             if(lookTarget.gameObject.activeSelf == false){
    49.                 lookTarget.gameObject.SetActive(true);  
    50.             }
    51.         }else{
    52.             for(int b = 0; b<localObjectsToDeactivate.Count;b++){
    53.                 localObjectsToDeactivate[b].SetActive(false);  
    54.             }
    55.             for(int c = 0; c<localScriptsToDeactivate.Count;c++){
    56.                 Destroy(localScriptsToDeactivate[c]);
    57.             }
    58.             Destroy(headLookController);
    59.         }
    60.         rmm = GameObject.FindWithTag("Network").GetComponent<RoomMultiplayerMenu>();
    61.     }
    62.      void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info){
    63.         if (stream.isWriting){
    64.             stream.SendNext(transform.position);
    65.             stream.SendNext(transform.rotation);
    66.             stream.SendNext(gameObject.name);
    67.             stream.SendNext(lookTarget.position);
    68.             stream.SendNext(lookTarget.rotation);
    69.             stream.SendNext((string)PhotonNetwork.player.customProperties["TeamName"]);
    70.             stream.SendNext(characterAnimation.animationSyncHelper);
    71.             stream.SendNext(characterAnimation.animationForHands);
    72.             stream.SendNext(characterAnimation.activeWeapon);
    73.             stream.SendNext(characterAnimation.animationType);
    74.         }else{
    75.             correctPlayerPos = (Vector3)stream.ReceiveNext();
    76.             correctPlayerRot = (Quaternion)stream.ReceiveNext();
    77.             PlayerName = (string)stream.ReceiveNext();
    78.             lookTargetPos = (Vector3)stream.ReceiveNext();
    79.              lookTargetRot = (Quaternion)stream.ReceiveNext();
    80.             playerTeam = (string)stream.ReceiveNext();
    81.             currentAnimation = (string)stream.ReceiveNext();
    82.             blendedAnimation = (string)stream.ReceiveNext();
    83.             currentWeaponName = (string)stream.ReceiveNext();
    84.             animType = (string)stream.ReceiveNext();
    85.         }
    86.     }
    87.     private Vector3 correctPlayerPos = new Vector3(0, -100, 0);
    88.     private Quaternion correctPlayerRot = Quaternion.identity;
    89.     private string PlayerName = "";
    90.     private Vector3 lookTargetPos = Vector3.zero;
    91.     private Quaternion lookTargetRot = Quaternion.identity;
    92.     private string playerTeam = "";
    93.     private string animType = "";
    94.     void Update(){
    95.         playerIsOurs = photonView.isMine;
    96.         if (!photonView.isMine){
    97.             transform.position = Vector3.Lerp(transform.position, correctPlayerPos, Time.deltaTime * 8);
    98.             transform.rotation = Quaternion.Lerp(transform.rotation, correctPlayerRot, Time.deltaTime * 8);
    99.             lookTarget.position = Vector3.Lerp(lookTarget.position, lookTargetPos, Time.deltaTime * 8);
    100.             lookTarget.rotation = lookTargetRot;
    101.            
    102.             if(gameObject.name != PlayerName){
    103.                 gameObject.name = PlayerName;
    104.             }
    105.             if(rmm.gameMode == "TDM"){
    106.                 if(playerTeam == (string)PhotonNetwork.player.customProperties["TeamName"]){
    107.                     playerDamage.disableDamage = true;
    108.                     drawPlayerName.enabled = true;
    109.                 }else{
    110.                     playerDamage.disableDamage = false;
    111.                     drawPlayerName.enabled = false;
    112.                 }
    113.             }else{
    114.                 drawPlayerName.enabled = false;
    115.             }
    116.             if(MovementAnimation != currentAnimation){
    117.                 MovementAnimation = currentAnimation;
    118.                 if(animType == "Walking"){
    119.                     headLookController.GetComponent<Animation>()[MovementAnimation].speed = animationSpeed.walkSpeed;
    120.                 }
    121.                 if(animType == "Running"){
    122.                     headLookController.GetComponent<Animation>()[MovementAnimation].speed = animationSpeed.runSpeed;
    123.                 }
    124.                 if(animType == "Crouch"){
    125.                     headLookController.GetComponent<Animation>()[MovementAnimation].speed = animationSpeed.crouchSpeed;
    126.                 }
    127.                 if(animType == "Prone"){
    128.                     headLookController.GetComponent<Animation>()[MovementAnimation].speed = animationSpeed.proneSpeed;
    129.                 }
    130.                
    131.                 if(headLookController.GetComponent<Animation>()[MovementAnimation] != null){
    132.                     headLookController.GetComponent<Animation>()[MovementAnimation].layer = 1;
    133.                     headLookController.GetComponent<Animation>()[MovementAnimation].wrapMode = WrapMode.Loop;
    134.                 }
    135.             }
    136.             if(headLookController.GetComponent<Animation>()[MovementAnimation] != null){
    137.                 headLookController.GetComponent<Animation>().CrossFade(MovementAnimation);
    138.             }
    139.            
    140.             if(currentBlendedAnimation != blendedAnimation){
    141.                 currentBlendedAnimation = blendedAnimation;
    142.                 if(!mixedAnimations.Contains(currentBlendedAnimation) && currentBlendedAnimation != "Null" && headLookController.GetComponent<Animation>()[currentBlendedAnimation] != null){
    143.                        headLookController.GetComponent<Animation>()[currentBlendedAnimation].layer = 4;
    144.                     headLookController.GetComponent<Animation>()[currentBlendedAnimation].wrapMode = WrapMode.Loop;
    145.                     headLookController.GetComponent<Animation>()[currentBlendedAnimation].AddMixingTransform(shoulderR);
    146.                     headLookController.GetComponent<Animation>()[currentBlendedAnimation].AddMixingTransform(shoulderL);  
    147.                     mixedAnimations.Add (currentBlendedAnimation);
    148.                 }
    149.             }
    150.             if(currentBlendedAnimation != "Null" && headLookController.GetComponent<Animation>()[currentBlendedAnimation] != null){
    151.                 headLookController.GetComponent<Animation>().Play(currentBlendedAnimation);
    152.             }
    153.             if(prevWeap != currentWeaponName){
    154.                 for(int i = 0; i < thirdPersonWeapons.childCount; i++){
    155.                     if(thirdPersonWeapons.GetChild(i).name != currentWeaponName){
    156.                         thirdPersonWeapons.GetChild(i).gameObject.SetActive(false);
    157.                     }else{
    158.                         thirdPersonWeapons.GetChild(i).gameObject.SetActive(true);
    159.                         currentActiveWeapon = thirdPersonWeapons.GetChild(i).gameObject;
    160.                     }
    161.                 }
    162.                 prevWeap = currentWeaponName;
    163.             }
    164.         }
    165.     }
    166.     public void ReDeactivatePlayerObjects(){
    167.         if(photonView.isMine){
    168.             for(int b = 0; b<localObjectsToDeactivate.Count;b++){
    169.                 localObjectsToDeactivate[b].SetActive(false);  
    170.             }
    171.             for(int c = 0; c<localScriptsToDeactivate.Count;c++){
    172.                 Destroy(localScriptsToDeactivate[c]);
    173.             }
    174.         }
    175.     }  
    176.     public void syncMachineGun(float errorAngle){
    177.         photonView.RPC ("SyncWeaponsRPC", PhotonTargets.Others, "syncMachineGun", errorAngle);
    178.     }
    179.     public void syncShotGun(int fractions){
    180.         photonView.RPC ("SyncWeaponsRPC", PhotonTargets.Others, "syncShotGun", (float)fractions);
    181.     }
    182.     public void syncGrenadeLauncher(float initialSpeed){
    183.         photonView.RPC ("SyncWeaponsRPC", PhotonTargets.Others, "syncGrenadeLauncher", initialSpeed);
    184.     }  
    185.     public void syncKnife(){
    186.         photonView.RPC ("SyncWeaponsRPC", PhotonTargets.Others, "syncKnife", 0.0f);
    187.     }  
    188.     [PunRPC]
    189.     void SyncWeaponsRPC(string functionName, float Value){
    190.         if(currentActiveWeapon){
    191.             currentActiveWeapon.SendMessage(functionName, Value, SendMessageOptions.DontRequireReceiver);
    192.         }
    193.     }
    194. }
     
  2. FedeStefan

    FedeStefan

    Joined:
    Aug 15, 2018
    Posts:
    221
    if i added more than 2 scripts, its cause they are togheter, they both need each other
    weapon sync needs player network, same with character animation