Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- // This script is attached to the pickup object. It ensures that the pickup object's
- // position, rotation and scale are kept up to date across the network.
- public class PickupMovementUpdate : MonoBehaviour {
- // Declare Variables
- private Vector3 lastPosition;
- private Quaternion lastRotation;
- private Transform myTransform;
- public bool amIBeingHeld = false;
- // Declare Variables end
- // Use this for initialization
- void Start ()
- {
- myTransform = transform;
- // Ensure that everyone sees the player at the correct location the moment they spawn
- //networkView.RPC ("updateMovement", RPCMode.OthersBuffered, myTransform.position, myTransform.rotation, myTransform.localScale);
- }
- // Update is called once per frame
- void Update ()
- {
- if (Network.peerType != NetworkPeerType.Disconnected && Network.isClient)
- {
- // If the object has moved at all, fire off an NPC to update the objects position and rotation across the network
- //Debug.Log("the cube's position is: " + myTransform.position);
- if (Vector3.Distance (myTransform.position, lastPosition) >= 0.1)
- {
- // Capture the pickup object's position before the RPC is fired off
- // Use this to determine if the object has moved in the if statement above
- lastPosition = myTransform.position;
- if (amIBeingHeld == false)
- {
- networkView.RPC ("updateMovement", RPCMode.AllBuffered, myTransform.position, myTransform.rotation, myTransform.localScale);
- }
- if (amIBeingHeld == true)
- {
- }
- }
- if (Quaternion.Angle (myTransform.rotation, lastRotation) >= 1)
- {
- // Capture the pickup object's rotation before the RPC is fired off
- // Use this to determine if the object has turned in the if statement above
- lastRotation = myTransform.rotation;
- networkView.RPC ("updateMovement", RPCMode.AllBuffered, myTransform.position, myTransform.rotation, myTransform.localScale);
- }
- }
- }
- // This ensures that the pickup object's position, rotation and scale are kept up to date across the network
- [RPC]
- void updateMovement (Vector3 newPosition, Quaternion newRotation, Vector3 newScale)
- {
- transform.position = newPosition;
- transform.rotation = newRotation;
- transform.localScale = newScale;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement