- Home /
Photon mirroring animation?
Hi, my photon app working fine, but 1 slice of code have a bug:
void Update() {
if (Input.GetKeyDown (KeyCode.R)) {
reload ();
}
if (rb.velocity.magnitude >= 0.5 && !graphicsAM.IsPlaying(tpRunReload.name)) {
if (!isTP) {
playAnim (walk.name);
} else {
graphicsPV.RPC ("playAnimPV", PhotonTargets.All, tpRun.name);
}
} else {
if (!graphicsAM.IsPlaying (tpReload.name)) {
if (!isTP) {
playAnim (iddle.name);
} else {
graphicsPV.RPC ("playAnimPV", PhotonTargets.All, tpIddle.name);
}
}
}
}
Reload working for all players (myself and OTHERS players reloading with me). How to solve this?
RPC call is here (+ anim method):
public void reload() {
graphicsPV.RPC ("playAnimPV", PhotonTargets.All, tpReload.name);
}
[PunRPC]
public void playAnimPV (string animName) {
if (isTP) {
graphicsAM.CrossFade (animName);
}
}
All anims working fine, but reload apply reload for all players (not ONLY myself, others players reloading with me same 1 touch over R key (on my game). How to solve this? Try isMine but cant work.
Thanks!
Answer by ChristianSimon · Oct 04, 2016 at 11:56 AM
If you press 'R' key right now, it is recognized by all characters since you don't differ between your character and other characters. To do so you can create a local reference to the PhotonView component. At the beginning of your class add PhotonView photonView;
without any assignment. The assignment is done in the Awake() oder Start() function where you add photonView = GetComponent<PhotonView>();
. Make sure to have a PhotonView component attached to the game object. At the beginning the Update() function add the following code:
if (!photonView.isMine)
{
return;
}
This checks if you are the owner of the current game object's Update() function. If you are not the owner nothing happens and the next object is updated. If you are the owner your source code is executed and the character reloads.
Your answer
![](https://koobas.hobune.stream/wayback/20220612093750im_/https://answers.unity.com/themes/thub/images/avi.jpg)