- Home /
How to play music and sound / get working radio
I am pretty noob at Unity. I am trying to make working radio and making it possibly the hardest way, but it's learning experience to me.
So I have that RadioStation changes when you click it under MaxDistance and it works but now I want to make music and changing channel button sound to play. Code to player
#pragma strict
var RadioChange : int = 1;
var Distance : float;
var MaxDistance : float = 3;
function Update ()
{
if (Input.GetButtonDown("Fire1"))
{
var hit : RaycastHit;
if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit))
{
Distance = hit.distance;
if (Distance < MaxDistance)
{
hit.transform.SendMessage("ApplyStationChange", RadioChange, SendMessageOptions.DontRequireReceiver);
}
}
}
}
Code on radio
#pragma strict
var RadioStation = 10;
function Update ()
{
if(RadioStation <= 0)
{
RadioStation = 10;
}
}
function ApplyStationChange (RadioChange : int)
{
RadioStation -= RadioChange;
}
RadioStation 10 is when radio is off and I want button click ofc to be first one and after that music, not same time.
So I would be thankful if you could help me in this. :)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613192105im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Trigger Start of Sound 1 Answer
What is the best way to convert MIDI to MP3? 1 Answer
Mute volume / sound problem 1 Answer
Sound effect doesn't play correctly 1 Answer
[NoBraves] Sound makes lag 1 Answer