- Home /
Toggle between Animation states over a network
I am using Mirror networking (Photon doesn't meet specific needs I have for Off-line LAN only connections) and I am trying to learn how to trigger animations and toggle between states over the network. My project is VR and while I have the VR player synchronizing head and hand movements and the player can take authority of objects to interact with them and move scene objects around I still don't know how to get animations to play on objects in the scene. The Network Animator script provided by mirror only seems to handle animations on the player such as walk cycles and jumping but I am needing a way to do things like animate the opening and closing of a door. An animation that needs to toggle between two (Possibly more) states.
I have started with the following script but so far its not doing anything and my local animations are not playing either when this script is present so I'm hoping someone here can help with a rewrite. I have left in some commented out code that I'm still playing with in case it inspires any ideas in other.
using UnityEngine;
using Mirror;
using Valve.VR;
public class SetNetworkAnimationTrigger : NetworkBehaviour
{
Animator AnimatorSource;
//public AnimationClip[] clip;
//public string[] AnimationStates;
public SteamVR_Action_Boolean triggerClick;
public bool playAnimationState = false;
public string playState;
private SteamVR_Input_Sources inputSource;
private int animState = 1;
// Start is called before the first frame update
void Start()
{
AnimatorSource = gameObject.GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
//AnimatorSource.SetBool(playState, playAnimationState);
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Networked")
{
triggerClick.AddOnStateDownListener(CmdAnimation, inputSource);
}
}
[Command]
private void CmdAnimation(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource)
{
AnimatorSource.enabled = !AnimatorSource.enabled;
animState = animState * (-1);
AnimatorSource.SetInteger(playState, animState);
//AnimatorSource.ResetTrigger("");
//AnimatorSource.SetTrigger("");
}
}
Thanks.
Your answer
![](https://koobas.hobune.stream/wayback/20220613012839im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Animations playing only in the Host and not on the clients - Unity Mirror Networking. 1 Answer
Oculus VR with Mirror multiplayer - headset is controlling both players 1 Answer
mirror animation sync 0 Answers
Override animation with bone rotation on Mirror Networking 0 Answers
Syncing Animation Across Network 0 Answers