Need Help Audiosource from Localplayer to Remoteplayer

Updated on January 2, 2016 in [A] Audio
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on January 2, 2016

I made the FPS Multiplayer Tutorial and added a few new things, but I would also add sounds. How do I get back the audiosource of localplayer also listen to remoteplayer? sorry for my bad English

using Unity engine;
using System.Collections;
using UnityEngine.Networking;

public class Player Shoot: NetworkBehaviour {

private const string PLAYER_TAG = “Player”;

Public Player Weapon weapon;
GameObject prefab;

[SerializeField]
Private Camera cam;

[SerializeField]
private LayerMask mask;

void start ()
{
if (cam == null)
{
Debug.LogError (“Player Shoot: No camera referenced”);
this.enabled = false;
}

Prefab = Resources.Load (“projectile”) as GameObject;
}

void update ()
{
if (Input.GetButton (“Fire1”) && time.time> weapon.nextFire)
{
weapon.nextFire = time.time + weapon.fireRate;
GameObject projectile = Instantiate (prefab) as GameObject;
projectile.transform.position = transform.position + cam.transform.forward * 1;
Rigidbody rb = projectile.GetComponent ();
rb.velocity = cam.transform.forward * weapon.range;

weapon.Audio.Play ();

Shoot ();
}
}

[Client]
void Shoot ()
{
RaycastHit _hit;
if (Physics.Raycast (cam.transform.position, cam.transform.forward, out _hit, weapon.range, mask))
{
if (_hit.collider.tag == PLAYER_TAG)
{
CmdPlayerShot (_hit.collider.name, weapon.damage);
}
}
}

[Command]
void CmdPlayerShot (string _playerID, int _damage)
{
Debug.log (_playerID + “has been shot.”);

Player _player = GameManager.GetPlayer (_playerID);
_player.RpcTakeDamage (_damage);
}

}

  • Liked by
Reply
0 on January 2, 2016

You could create an array of the sounds the player can make. When you want to play it, then you could do that with a Command/Rpc call.

  • Liked by
Reply
Cancel
0 on January 2, 2016

@Dion Dokter 

But how do I do that? I since yesterday been sitting because I’m at this point simply can not continue. Could you tell me on any example how can I make the order that the learning effect is also present?

  • Liked by
Reply
Cancel