Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Mrmudweasel · Aug 29, 2015 at 02:50 PM · animationjavascriptnetworkingrpc

Network animations playing on all player models whenever any player moves.

I'm working on a multiplayer game and I have a animation manager that sends RPC's to all the players telling them to play the walking and idle animations on the player that called it, it's not working though. Whenever any player moves all of the players play the walking animation instead of just the person walking. If you guys could help me with this I'd owe you a solid.

 #pragma strict
     var anim : Animation;
  function Start()
  {
   }
 
  function Update () 
      {
          if(GetComponent.<NetworkView>().isMine)
          {
              if(Input.GetKeyUp(KeyCode.W)||Input.GetKeyUp(KeyCode.A)||Input.GetKeyUp(KeyCode.S)||Input.GetKeyUp(KeyCode.D))
                  GetComponent.<NetworkView>().RPC("IdleAnimation", RPCMode.All);        
   
             // if (Input.GetButtonDown("Fire1")) 
             // {
                  //Attack animation
                 // networkView.RPC("PuchAnimation", RPCMode.All);    
   
             // }
           //   if (Input.GetButtonDown("Fire2")) 
            //  {
              //Attack animation
            //      networkView.RPC("Attack3Animation", RPCMode.All);    
      
              }
              if (Input.GetKey(KeyCode.W)||Input.GetKey(KeyCode.A)||Input.GetKey(KeyCode.D)||Input.GetKey(KeyCode.S)) 
              {
                  //Attack animation
                  GetComponent.<NetworkView>().RPC("WalkAnimation", RPCMode.All);    
              }
              if(Input.GetKeyDown(KeyCode.Space))
                  GetComponent.<NetworkView>().RPC("JumpAnimation", RPCMode.All);    
   
          }
 
      
      @RPC //IDLEANIMATION RPC
      function IdleAnimation ()
      {
          GetComponent.<Animation>().CrossFade("Idle"); 
      }
      
    //  @RPC //PUNCHANIMATIONRPC
     // function PunchAnimation ()
     // {
     //     animation.CrossFade("punch"); 
     // }
      
     // @RPC ATTACK3ANIMTION RPC
    //  function Attack3Animation ()
    //  {
     //     animation.CrossFade("attack3"); 
     // }
      
      @RPC //WALK ANIMATION RPC
      function WalkAnimation ()
      {
          GetComponent.<Animation>().CrossFade("Walk"); 
      }
      
      @RPC //JUMP ANIMATION RPC 
      function JumpAnimation ()
      {
          GetComponent.<Animation>().CrossFade("jump"); 
      }
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Wolfrik_Creations · Nov 29, 2015 at 01:37 AM

Correct me if I'm wrong but it looks like your other functions are a part of the Update function but I may just be crazy. Here I wrote a code that should work for you, but you will need to create an animation for walking left, right, and backwards if that's not too much trouble. If so I can remake another script.

 #pragma strict
 
 function Start () {
     GetComponent.<NetworkView>().RPC("Idle", RPCMode.All);  
 }
 
 function Update () {
     if(GetComponent.<NetworkView>().isMine){
         if(Input.GetKey(KeyCode.W)) {
             GetComponent.<NetworkView>().RPC("WalkAnim", RPCMode.All);  
         }
         if(Input.GetKey(KeyCode.Space)) {
             GetComponent.<NetworkView>().RPC("Jump", RPCMode.All);  
         }
         if(Input.GetKeyUp(KeyCode.W)) {
             GetComponent.<NetworkView>().RPC("Idle", RPCMode.All);  
         }
         if(Input.GetKey(KeyCode.A)) {
             GetComponent.<NetworkView>().RPC("StrafingLeftF", RPCMode.All);  
         }
         if(Input.GetKeyUp(KeyCode.A)) {
             GetComponent.<NetworkView>().RPC("Idle", RPCMode.All);  
         }
         if(Input.GetKey(KeyCode.D)) {
             GetComponent.<NetworkView>().RPC("StrafingRightF", RPCMode.All);  
         }
         if(Input.GetKeyUp(KeyCode.D)) {
             GetComponent.<NetworkView>().RPC("Idle", RPCMode.All);  
         }
         if(Input.GetKey(KeyCode.S)) {
             GetComponent.<NetworkView>().RPC("WalkingBackwards", RPCMode.All);  
         }
         if(Input.GetKeyUp(KeyCode.S)) {
             GetComponent.<NetworkView>().RPC("Idle", RPCMode.All);  
         }
         if(Input.GetMouseButtonDown(0)) {
             //ATTACK ANIM HERE
         }
     }
     else{enabled=false;}
 }
 
 @RPC
 function Idle () {
     idle=false;
     GetComponent.<Animation>().CrossFade("Idleation");
 }
 @RPC
 function Jump () {
     GetComponent.<Animation>().CrossFade("jump");
     yield WaitForSeconds(1);//YOUR JUMP TIME IN THOSE PARENTHESES
     GetComponent.<Animation>().CrossFade("Idle");
 }
 @RPC
 function WalkingBackwards () {
     GetComponent.<Animation>().CrossFade("WalkingBack");
 }
 
 @RPC
 function WalkAnim () {
     GetComponent.<Animation>().CrossFade("Walking");
 }
 @RPC
 function StrafingLeftF () {
     GetComponent.<Animation>().CrossFade("StrafingLeft");
 }
 @RPC
 function StrafingRightF () {
     GetComponent.<Animation>().CrossFade("StrafingRight");
 }
 
 @RPC
 function PunchAnim () {
     //MAKE THE PUNCH ANIM RUN AN RPC TO THIS
 }

If you don't want to use this I'm pretty sure the problem is that you need to have after your GetComponent..isMine you need to put else{enabled=false;}

also if I were you I'd use GetMouseButtonDown(0) rather than GetButtonDown("fire1")

:D

Comment
Add comment · Show 1 · Share
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 Wolfrik_Creations · Nov 29, 2015 at 01:41 AM 0
Share

Also if you have any questions you can add my Skype israel.boone1 because I'm experienced with JS and a bit of C# but I'm also learning multiplayer right now and can help you with any problems you have. :D

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Help with bullet going in the dirrection fired from view of camera?? 1 Answer

Setting function to run on all clients but only work on the player that called it 0 Answers

UNET: Network [Command] from non-player object 0 Answers

Player attacking enemy script 0 Answers

I want my character to enter and exit car with animation 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