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 Amer ALhwifi · Apr 11, 2014 at 12:08 AM · networkingaudiofpsphotonsync

Syncing FPS Firing Sound over network via RPC {PHOTON}

Hello Guys , I'm having troubles with @RPC to sync My sounds on the network . I want to Sync the Firing Sound , so the other players can hear it .

Here is my sound code :

     var drawAnim : String = "";             // animation of taking out weapon.
     var drawReturnAnim : String = "";        // putting back weapon (playing draw animation backwards)
     var fireAnim : String = "";                
     var reloadAnim : String = "";
     var fireEmptyAnim : String = "";      //if you dont have this specific animation, you can use your "Fire" animation. 
     var idleAnim : String = "";
     var drawAnimSpeed : float = 1.0;
     var drawReturnSpeed : float = 2.0;
     var reloadAnimSpeed : float = 1.0;
     var fireSound : AudioClip;
     var soundGO : GameObject;
     var drawSound : AudioClip;
     var reloadSound : AudioClip;
     var outOfAmmo : AudioClip;
     
     //Shotgun Animations
     var startReload : String = "StartReload";
     var insertBullet : String = "Insert";
     var endReload : String = "AfterReload";
     var SGinsert : AudioClip;
     var SGpump : AudioClip;
     var weaponScript : WeaponScript;
     //Only for Crossbow
     var idleLoadedAnim : String = "";
     
     var audioShellEject : AudioClip;
     private var step : boolean = true;
     
     function OnEnable () {
     step = true;
 }
 
 function Start(){
     //animation.wrapMode = WrapMode.Once;
     if(idleAnim != "") animation[idleAnim].wrapMode = WrapMode.Loop;
     if(idleLoadedAnim != "") animation[idleLoadedAnim].wrapMode = WrapMode.Loop;
     if(weaponScript.typeOfFireMode == fireMode.Shotgun){
         animation[endReload].layer = 5;
     }
 }
 
 function Update(){
     if(idleAnim != ""){
         if(!animation.isPlaying){
         
             if(weaponScript.typeOfFireMode == fireMode.Launcher){
                 if(weaponScript.numberOfClips == 0){
                     animation.CrossFadeQueued(idleLoadedAnim, 0.3, QueueMode.PlayNow);
                 }else{
                     animation.CrossFadeQueued(idleAnim, 0.3, QueueMode.PlayNow);
                 }    
             }else{
                 
                 if(weaponScript.reloading == false) animation.CrossFadeQueued(idleAnim, 0.8, QueueMode.PlayNow);
             }
         }    
     }
 }
     @RPC 
 function PlayOutOfAmmo(){
     step = false;
 
     if(!animation.IsPlaying(fireAnim)){
         if(fireEmptyAnim != ""){
             PlayAudioClip(outOfAmmo, transform.position, 1.0);
             animation.Rewind(fireEmptyAnim);
             animation.Play(fireEmptyAnim);
                 step = true;
 
         }    
     }
 }
 
 @RPC 
     
 
 function PlayAudioEject(){
     step = false;
 
     audio.PlayOneShot(audioShellEject, 1.0);
         step = true;
 
 }
 @RPC 
 function ReturnReloading(){
     step = false;
 
     if(idleAnim != ""){
     
         if(weaponScript.typeOfFireMode == fireMode.Launcher){
             if(weaponScript.bulletsLeft == 0){
                 animation.CrossFadeQueued(idleLoadedAnim, 0.5, QueueMode.PlayNow);
                 //audio.Stop();
                 //animation.Play(idleLoadedAnim);
             }else{
                 animation.CrossFadeQueued(idleAnim, 0.01, QueueMode.PlayNow);
                 audio.Stop();
                 animation.Play(idleAnim);
             }
             soundGO.audio.Stop();
             audio.Stop();
         }else if(weaponScript.typeOfFireMode == fireMode.Shotgun){
             //animation.CrossFadeQueued(idleAnim, 0.9, QueueMode.PlayNow);
             soundGO.audio.Stop();
             audio.Stop();
             animation.Play(idleAnim);
         
         }else{
             animation.CrossFade(idleAnim, 0.2);
             soundGO.audio.Stop();
             audio.Stop();
                 step = true;
 
         }
     }
 }
 @RPC 
 function PlayFireAnimAuto(){
     step = false;
 
     if(fireAnim != ""){
         animation.Rewind(fireAnim);
         animation.Play(fireAnim);
         //audio.PlayOneShot(fireSound,1.0);
         PlayAudioClip(fireSound, transform.position, 1.0);
             step = true;
 
     }    
 }
 @RPC 
 function PlayFireAnimSemi(){
     step = false;
 
     if(fireAnim != ""){
         animation.CrossFadeQueued(fireAnim, 0.1, QueueMode.PlayNow);
         //PlayAudioClip(fireSound, transform.position, 0.7);
         audio.clip = fireSound;
         audio.volume = 1.0;
         audio.Play();
             step = true;
 
     }
 }
 
 function DrawWeapon(){
     if(drawAnim != ""){
         soundGO.audio.Stop();
         audio.clip = drawSound;
         audio.volume = 0.7;
         audio.Play();
         animation.Stop(drawAnim);
         animation[drawAnim].speed = drawAnimSpeed; 
         animation.Play(drawAnim);
     }
 }
 
 function PutDownWeapon(){
     if(drawReturnAnim != ""){
         audio.clip = drawSound;
         audio.volume = 0.7;
         audio.Play();
         animation[drawReturnAnim].speed = drawReturnSpeed;
         animation.Play(drawReturnAnim);
     }
 }
 
 function QuickPutDownWeapon(){
     if(drawReturnAnim != ""){
         animation[drawReturnAnim].speed = drawReturnSpeed*2;
         animation.CrossFade(drawReturnAnim);
     }    
 }
 
 function ReloadWeapon(){
     if(reloadAnim != ""){
         soundGO.audio.clip = reloadSound;
         soundGO.audio.volume = 1.0;
         soundGO.audio.Play();
         animation[reloadAnim].speed = reloadAnimSpeed;
         animation.Play(reloadAnim);
     }    
 }
 
 //Shotgun
 function ReloadStart(){
     animation[startReload].time = 0.0;
     animation.Play(startReload);
 }
  @RPC 
 function InsertBullet(){
     animation[insertBullet].time = 0.0;
     //animation.Rewind(insertBullet);
     animation.PlayQueued(insertBullet, QueueMode.PlayNow);
     //animation.Play(insertBullet);
     audio.PlayOneShot(SGinsert, 1.0);
 }
  @RPC 
 function ReloadStop(){
     animation[endReload].speed = 2;
     animation.Play(endReload);
     yield WaitForSeconds(0.2);//delay, before sound will start play.
     audio.clip = SGpump;
     audio.volume = 1.0;
     audio.Play();
     
 }
 function ResetReloading(){
     soundGO.audio.Stop();
     audio.Stop();
     animation.Stop();
     animation[insertBullet].time = 0.0;
     animation[startReload].time = 0.0;
 }
 
 function PlayAudioClip (clip : AudioClip, position : Vector3, volume : float) {
     var go = new GameObject ("One shot audio");
     go.transform.position = position;
     var source : AudioSource = go.AddComponent (AudioSource);
     source.clip = clip;
     source.volume = volume;
     source.pitch = Time.timeScale;
     source.Play ();
     Destroy (go, clip.length);
     return source;
 }

Just tell me how . Any Help will be highly appreciated !

Thanks in Advance!

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 javerwocky · Jan 07, 2016 at 08:23 AM 0
Share

did you figure it out please share .

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

22 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

Related Questions

Photon Networking Instantiating Problem 0 Answers

Photon only shows host their changes to players, not other way around 1 Answer

Unity PhotonNetwork globally enable a component 1 Answer

how to sync audio in instantiated object so all players can hear it? 0 Answers

Photonview "this" does not exist in current context 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