- Home /
Getting weird effects from audio clip
The first problem is when the audio clip plays. I just want it to play when a unit/units are selected. However its playing every time I release the left mouse button?
using UnityEngine;
using System.Collections;
public class Unit : MonoBehaviour
{
public Projector lightRing;
public AudioClip YesSir;
public bool selected = false;
void Start()
{
lightRing = GetComponentInChildren<Projector>();
}
private void Update()
{
if(renderer.isVisible && Input.GetMouseButton(0))
{
Vector3 camPos = Camera.main.WorldToScreenPoint(transform.position);
camPos.y = CameraOperator.InvertMouseY(camPos.y);
selected = CameraOperator.selection.Contains(camPos);
}
if(selected)
lightRing.enabled = true;
else
lightRing.enabled = false;
if(renderer.isVisible && lightRing.enabled == false && Input.GetMouseButtonUp(0))
{
ConfirmCommand();
}
}
private void ConfirmCommand()
{
audio.PlayOneShot(YesSir);
}
}
The 2nd issue is the more Units I select the quieter the sound clip plays! (one or two units is fine, 3 - 5 its barely audible and 6 or more and you just cant hear anything)
Why is the volume apparently being shared between the number of units?
Any ideas please guys ???
WTH... can't believe I didn't notice that.
Thanks.
Answer by chariot · Feb 11, 2015 at 02:06 PM
Change lightRing.enabled == false; to lightRing.enabled == true;. U needed to play sound when char are selected, so why you use "false"?
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Forward and Backward 3D sound? 1 Answer
Controlling Master Volume with one slider? 1 Answer
Is OnAudioFilterRead Still the Preferred Method for Procedural Audio? 0 Answers
Multiple Cars not working 1 Answer