When the player spawns in game, an EquipWeapon method is played at start, which first sets the weapon as the child of a weaponHolder object on the players right hand, then locally transforms the weapon on the weaponHolder. This works fine for the host. I can see that in the game and scene view it is correctly placed. When I spawn a client, the clients weapon also spawns correctly for the client in scene and game view. However, when the client walks up to the host, the hosts sword appears incorrectly (screenshots attached). The client game view of the host and the scene view are out of sync with regards to the sword position, which is the issue.
I suspect it has something to do with the transform to local position and how EquipWeapon is called. Is there a way to adjust it so that it appears the same between client and host and client to host?
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
[System.Obsolete]
public class WeaponManager : NetworkBehaviour
{
[SerializeField]
private Transform weaponHolder;
[SerializeField]
private PlayerWeapon primaryWeapon;
private PlayerWeapon currentWeapon;
private GameObject weaponIns;
void Start()
{
EquipWeapon(primaryWeapon);
}
public PlayerWeapon GetCurrentWeapon()
{
return currentWeapon;
}
void EquipWeapon (PlayerWeapon weapon)
{
currentWeapon = weapon;
weaponIns = (GameObject)Instantiate(weapon.graphics, weaponHolder.position, Quaternion.Euler(weapon.rotation), weaponHolder);
weaponIns.transform.localPosition = weapon.position;
}
}
Weapon class (just in case):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class PlayerWeapon
{
public string name = "Longsword";
public int damage = 10;
public float range = 0.8f;
public GameObject graphics;
public Vector3 position = new Vector3(-.07f, 2.329f, 1.281f);
public Vector3 rotation = new Vector3(0f, 90f, 22.221f);
}

