- Home /
Photon Play Animation
Hi Everyone! How can i play animation with Photon? (without animator)
Answer by 334499p · Aug 15, 2015 at 07:54 AM
What you are asking is kind of generic so...
PUN has two types of network objects... player network objects and scene objects. A scene object is an object that is owned by the photon network and if the masterclient leaves then it remains in the game (great for enemies). Player network objects are more temporary objects and only exist as long as their owners are connected. So the player model could be a player network object and is controlled directly by that player, not the scene. For scene objects you need to use RPC calls to update information across the network but for player network objects it could get more complicated if you want to increase optimization/limit your RPC calls by using OnPhotonSerializeView. Any type of object that's going to be synced across the network (besides preplaced map details) is going to require a PhotonView. So for your object with the animation an RPC call is probably the best way to go about it because i'm not sure if its a scene object or not.
On the object that you are animating add a PhotonView and then create a script and add the following to the Update() function:
if(Input.GeyKeyDown(KeyCode.Space)){
GetComponent<PhotonView>().RPC("playAnimation", PhotonTargets.All, null);
}
add the following RPC call after the Update() Function:
[RPC]
void playAnimation(){
GetComponent<Animation>().Play();
}
What this script does is activate the object's animation if a player presses the space bar. When the space bar is pressed then the PhotonView on the object tells its self across the network to play the animation. This script functions whether or not the object is a scene object or player object. The object is present on every client across the network but it is unaware if itself across the network. Using the RPC call tells its PhotonView to communicate with itself across the network to let itself to execute the animation.
Your answer
Follow this Question
Related Questions
Can we use "Photon cloud" for a card game like poker in Unity3d? 1 Answer
Photon Networking - Getting RoomList inside a Room 1 Answer
Photon Networking Player Control Issue 1 Answer
Photon Syncing Animations 2 Answers
Two Photon problems 0 Answers