Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by HuskyPanda213 · Jun 11, 2013 at 08:49 PM · networkanimations

Network animation sync, problem.

Hello, I have a networked game, and tried to make the animations sync for my third person viewed guy(The guy displayed over the network.), but it does not play the animations. I have a Empty game object called player with the scripts UserPlayer and NetworkAnimation(Also a network view) applied to it, then a ThirdPerson viewed object with an animation component(And all stated animations), and a First person object, with Network animation controller attached. Also all Variables were assigned, here are all my scripts.

UserPlayer:

 using UnityEngine;
 using System.Collections;
 
 public class UserPlayer : MonoBehaviour {
     public Transform FirstPerson;
     public WeaponManager FirstPersonCont;
     public Transform ThirdPerson;
     public Player MyPlayer;
     public GameObject Ragdoll;
     
     public Vector3 CurPos;
     public Quaternion CurRot;
     // Use this for initialization
     void Start () {
         MyPlayer = NetworkManager.GetPlayer(networkView.owner);
         MyPlayer.Manager = this;
         FirstPerson.gameObject.SetActive(false);
         ThirdPerson.gameObject.SetActive(false);
         DontDestroyOnLoad(gameObject);
     }
     
     // Update is called once per frame
     void Update () {
     
     }
     
     [RPC]
     void Server_TakeDamage(float Damage){
         networkView.RPC("Client_TakeDamage",RPCMode.Server,Damage);
     }
     
     [RPC]
     void Client_TakeDamage(float Damage){
         MyPlayer.Health -= Damage;
         Debug.Log("Player Has Been Shot!  " + MyPlayer.Health);
         if(MyPlayer.Health <= 0){
             networkView.RPC("Die",RPCMode.All);
             MyPlayer.isAlive = false;
             MyPlayer.Health = 0;
             Instantiate(Ragdoll,ThirdPerson.position,ThirdPerson.rotation);
         }
             
     }
     
     [RPC]
     void Spawn(){
         MyPlayer.Health = 100;
         MyPlayer.isAlive = true;
         if(networkView.isMine){
             FirstPerson.gameObject.SetActive(true);
             ThirdPerson.gameObject.SetActive(false);
         }
         else{
             FirstPerson.gameObject.SetActive(false);
             ThirdPerson.gameObject.SetActive(true);
         }
     }
     [RPC]
     void Die(){
         MyPlayer.isAlive = false;
         FirstPerson.gameObject.SetActive(false);
         ThirdPerson.gameObject.SetActive(false);
         
     }
     void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info){
         if(stream.isWriting){
             CurPos = FirstPerson.position;
             CurRot = FirstPerson.rotation;
             stream.Serialize(ref CurPos);
             stream.Serialize(ref CurRot);
             char Ani = (char)GetComponent<NetworkAnimation>().CurrentAnim;
             stream.Serialize(ref Ani);
         }
         else{
             stream.Serialize(ref CurPos);
             stream.Serialize(ref CurRot);
             ThirdPerson.position = CurPos;
             ThirdPerson.rotation = CurRot;
             char Ani = (char)0;
             stream.Serialize(ref Ani);
             GetComponent<NetworkAnimation>().CurrentAnim = (Animations)Ani;
             
         }
     }
 }



 NetworkAnimation:

 using UnityEngine;
 using System.Collections;
 using System;
 
 public class NetworkAnimation : MonoBehaviour {
     public Animations CurrentAnim = Animations.Primary_Idle_1;
     public GameObject ThirdPersonPlayer;
     
     void Update(){
         ThirdPersonPlayer.animation.CrossFade(Enum.GetName(typeof(Animations),CurrentAnim));
     }
     
     public void SyncAnim(string animname, float Speed){
         CurrentAnim = (Animations)Enum.Parse(typeof(Animations),animname);
         animation[CurrentAnim.ToString()].speed = Speed;
     }
 }
 
 
 public enum Animations{
     Primary_Idle_1,
     Primary_Walk_1,
     Primary_Reload_1
 }


 Network Animation Controller:



     using UnityEngine;
 using System.Collections;
 
 public class NetworkAnimationController : MonoBehaviour {
 
     public float V;
     public float H;
     public NetworkAnimation States;
     
     
     void Update(){
         V = Input.GetAxis("Vertical");
         H = Input.GetAxis("Horizontal");
         
         if(V < 0){
             States.SyncAnim("Primary_Walk_1",1);
         }
         if(V > 0){
             States.SyncAnim("Primary_Walk_1",1);
         }
         else{
             States.SyncAnim("Primary_Idle_1",1);
         }
         
     }
     
 }
Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Benproductions1 · Jun 12, 2013 at 04:15 AM 0
Share

Do you get any errors? Have you tried debugging your script? If so what are your results? If not, please do so before you ask questions

avatar image HuskyPanda213 · Jun 13, 2013 at 04:45 PM 0
Share

No errors with code, if I put thirdperson.animation.speed thing, did you see anything wrong with the code.

avatar image Jamora · Jun 13, 2013 at 11:37 PM 0
Share

Is your NetworkView actually observing the component you want to transfer over the network? They default to the Transform of the GameObject they're attached.

avatar image HuskyPanda213 · Jun 18, 2013 at 02:31 AM 0
Share

Yes the user player is being observed, but it just isnt playing the animations, and the animations are named right for what im asking from the script. Did you see anything wrong?

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Unhandled message error when registering host 1 Answer

Animations not working like they should 0 Answers

Make an animation play over RPC call? 1 Answer

Network FPS Scripting Help 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges