public void Update() { if (IsHeld) { Transform ActorHead = OwnerPlayerActor.GetComponent <CPlayerHead>().ActorHead.transform; gameObject.transform.rotation = ActorHead.rotation; } }
public void OnNetworkVarSync(INetworkVar _cVarInstance) { if (_cVarInstance == m_ulOwnerPlayerId) { if (IsHeld) { GameObject cOwnerPlayerActor = OwnerPlayerActor; Transform[] children = OwnerPlayerActor.GetComponentsInChildren <Transform>(); foreach (Transform child in children) { if (child.name == "RightHandIndex2") { gameObject.transform.parent = child; } } if (gameObject.transform.parent.gameObject == null) { Debug.LogError("Could not find right hand transform of player model!"); } gameObject.transform.localPosition = new Vector3(0.0f, 0.0f, 0.0f); // Turn off dynamic physics if (CNetwork.IsServer) { rigidbody.isKinematic = true; rigidbody.detectCollisions = false; } // Stop recieving syncronizations GetComponent <CActorNetworkSyncronized>().m_SyncPosition = false; GetComponent <CActorNetworkSyncronized>().m_SyncRotation = false; } else { gameObject.transform.parent = null; // Turn on dynamic physics if (CNetwork.IsServer) { rigidbody.isKinematic = false; rigidbody.detectCollisions = true; } rigidbody.AddForce(transform.forward * 5.0f, ForceMode.VelocityChange); rigidbody.AddForce(Vector3.up * 5.0f, ForceMode.VelocityChange); // Recieve syncronizations GetComponent <CActorNetworkSyncronized>().m_SyncPosition = true; GetComponent <CActorNetworkSyncronized>().m_SyncRotation = true; } } }