Not sycn JumpAnim
Options
Why "isJumping" anim work on my pc but is not sync?
using UnityEngine;
using System.Collections;
public class JumpAndRunMovement : MonoBehaviour
{
public float Speed;
public float JumpForce;
Animator m_Animator;
Rigidbody m_Body;
PhotonView m_PhotonView;
bool m_IsGrounded = false;
public bool jump = false;
void Awake()
{
m_Animator = GetComponent();
m_Body = GetComponent();
m_PhotonView = GetComponent();
}
void Update()
{
UpdateIsRunning();
UpdateFacingDirection();
if (jump == false)
{
m_PhotonView.RPC("grunded", PhotonTargets.All);
}
}
void FixedUpdate()
{
if (m_PhotonView.isMine == false)
{
return;
}
UpdateMovement();
UpdateJumping();
}
void UpdateFacingDirection()
{
if (m_Body.velocity.x > 0.2f)
{
transform.localScale = new Vector3(1, 1, 1);
}
else if (m_Body.velocity.x < -0.2f)
{
transform.localScale = new Vector3(-1, 1, 1);
}
}
void UpdateJumping()
{
if (Input.GetKey(KeyCode.Space) == true && m_IsGrounded == true)
{
jump = true;
if (jump)
{
m_Body.AddForce(Vector2.up * JumpForce);
jump = false;
m_IsGrounded = false;
print("Jump");
m_PhotonView.RPC("DoJump", PhotonTargets.Others);
}
}
}
[PunRPC]
void DoJump()
{
print("cos");
m_Animator.SetTrigger("IsJumping");
}
[PunRPC]
void grunded()
{
m_Animator.SetBool("IsGrounded", m_IsGrounded);
}
void UpdateMovement()
{
Vector2 movementVelocity = m_Body.velocity;
if (Input.GetAxisRaw("Horizontal") > 0.5f)
{
movementVelocity.x = Speed;
}
else if (Input.GetAxisRaw("Horizontal") < -0.5f)
{
movementVelocity.x = -Speed;
}
else
{
movementVelocity.x = 0;
}
m_Body.velocity = movementVelocity;
}
void UpdateIsRunning()
{
m_Animator.SetBool("IsRunning", Mathf.Abs(m_Body.velocity.x) > 0.1f);
}
void OnCollisionEnter(Collision hit)
{
m_IsGrounded = true;
print("grounded");
}
}
0