public void RpcPlay3DItemSound(string region, int ID, Defs.ItemSound target, Vector3 position, float volume, float distanceMin, float distanceMax, float pitchMin, float pitchMax) { bool criteria = false; GameObject[] players = GameObject.FindGameObjectsWithTag("Player"); for (int count = 0; count < players.Length; count++) { if (players[count].GetComponent <Player>().isLocalPlayer) { if (players[count].GetComponent <PlayerCore>().currentLocation == region) { criteria = true; } break; } } if (criteria) { Item targetItem = MasterListDatabase.i.FetchItem(ID); AudioClip[] clips; AudioClip targetClip; switch (target) { case Defs.ItemSound.WindupSound: clips = targetItem.WindupSound; break; case Defs.ItemSound.StrikeSound: clips = targetItem.StrikeSound; break; case Defs.ItemSound.HitSound: clips = targetItem.HitSound; break; case Defs.ItemSound.FlightSound: clips = targetItem.FlightSound; break; case Defs.ItemSound.BlockSound: clips = targetItem.BlockSound; break; default: clips = null; Debug.Log("No Sounds Defined!"); break; } if (clips != null && clips.Length != 0) { GameObject spawned = Instantiate(spawnSource, position, new Quaternion()); AudioSource source = spawned.GetComponent <AudioSource>(); targetClip = clips[Random.Range(0, clips.Length)]; source.clip = targetClip; source.volume = volume; source.minDistance = distanceMin; source.maxDistance = distanceMax; source.pitch = Random.Range(pitchMin, pitchMax); source.Play(); //Destroy When Complete Destroy(spawned, targetClip.length + 0.1f); } } }
public void CmdPlay3DItemSound(string region, int ID, Defs.ItemSound target, Vector3 position, float volume, float distanceMin, float distanceMax, float pitchMin, float pitchMax) { RpcPlay3DItemSound(region, ID, target, position, volume, distanceMin, distanceMax, pitchMin, pitchMax); }