Animations
Last updated
Was this helpful?
Was this helpful?
using UnityEngine;
using Coherence.Toolkit;
using System.Collections.Generic;
public class JumpController : MonoBehaviour
{
static List<CoherenceSync> instances = new List<CoherenceSync>();
CoherenceSync coherenceSync;
Animator animator;
void Awake()
{
coherenceSync = GetComponent<CoherenceSync>();
animator = GetComponent<Animator>();
}
void OnEnable()
{
instances.Add(coherenceSync);
}
void OnDisable()
{
instances.Remove(coherenceSync);
}
void Update()
{
if (!coherenceSync.isSimulated)
{
return;
}
if (Input.GetKeyDown(KeyCode.Space))
{
MakePlayerJump();
}
}
void MakePlayerJump()
{
animator.SetTrigger("Jump");
// TODO move your character up
NotifyJumpOverNetwork(coherenceSync);
}
// bind to this method via the Bindings window
public void PlayJumpAnimation(CoherenceSync target)
{
var animator = target.GetComponent<Animator>();
animator.SetTrigger("Jump");
}
void NotifyJumpOverNetwork(CoherenceSync whoJumped)
{
foreach (var s in instances)
{
if (!s || s == whoJumped)
{
continue;
}
s.SendCommand("JumpController.PlayJumpAnimation", whoJumped);
}
}
}