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 midgear · Oct 17, 2018 at 07:44 PM · networkingphoton

PUN 2 door Animator problem

I'm making a game with PUN2 and and most everything is working but I have a automatic door that is causing me some problems. The Animator on the door is working player side for all characters, but it only plays across the server when whoever is hosting the walks to the door: alt text But if the player who is not hosting walks into the door it will play for her but not across the server to all players: alt text I've done everything I can think of and am out of ideas. here is the script so you can see what's going on:

 using UnityEngine;
 using System.Collections;
 
 public class Animation_door : MonoBehaviour {
 
     Animator anim;
     public AudioClip doorOpenClip;
     public AudioClip doorCloseClip;
 
     void Start()
     {
         anim = GetComponent<Animator>();
     }
     void OnTriggerEnter(Collider other) {
         if(other.GetComponent<Collider>().tag=="Player")
         {
             anim.SetBool("Open",true);
             GetComponent<AudioSource>().clip = doorOpenClip;
             GetComponent<AudioSource>().Play();
         }
     }
     void OnTriggerExit(Collider other) {
         if(other.GetComponent<Collider>().tag=="Player")
         {
             anim.SetBool("Open",false);
             GetComponent<AudioSource>().clip = doorCloseClip;
             GetComponent<AudioSource>().Play();
         }
     }
 }
 


001.png (472.9 kB)
002.png (458.6 kB)
Comment
Add comment · Show 1
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 NoDumbQuestion · Oct 18, 2018 at 03:17 AM 1
Share

Where is the netcode?

I guess the door only allow authority for server (server own the door and not allow client change animation state) and not client => client cannot call door open on everyone.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by midgear · Oct 26, 2018 at 09:45 PM

Okay I got it working here is the code:

 using UnityEngine;
 using System.Collections;
 using Photon.Pun;
 
 [RequireComponent(typeof(PhotonView))]
 [RequireComponent(typeof(PhotonAnimatorView))]
 
 public class Animation_door : MonoBehaviourPun
 {
     //PhotonView photonView = PhotonView.Get(this);
     public bool enter = false;
 
     Animator anim;
     public AudioClip doorOpenClip;
     public AudioClip doorCloseClip;
 
 
     void Start()
     {
         anim = GetComponent<Animator>();
     }
 
     void OnTriggerEnter(Collider other)
     {
         if (other.gameObject.tag == "Player")
         {
             photonView.RPC("openDoor", RpcTarget.All, null);
         }
     }
 
     void OnTriggerExit(Collider other)
     {
         if (other.gameObject.tag == "Player")
         {
             photonView.RPC("closeDoor", RpcTarget.All, null);
         }
     }
 
     [PunRPC]
     void closeDoor()
     {
         //Debug.Log("Trigger Exit");
         (enter) = false;
 
         anim.SetBool("Open",false);
         GetComponent<AudioSource>().clip = doorCloseClip;
         GetComponent<AudioSource>().Play();
     }
 
     [PunRPC]
     void openDoor()
     {
         //Debug.Log("Trigger Enter");
         (enter) = true;
 
         anim.SetBool("Open",true);
         GetComponent<AudioSource>().clip = doorOpenClip;
         GetComponent<AudioSource>().Play();
 
     }
 
 
 }
 
Comment
Add comment · 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

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

202 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 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 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 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 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 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 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 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 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 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 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 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

What's wrong with my script ? 0 Answers

Unity Photon Player Instantiation 1 Answer

Photon RPC Parameter NullReferenceException 1 Answer

I get an error message every time i run this script? Any ideas? 0 Answers

How do I sync health meters via Photon? 0 Answers


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