I want to switch On a radio, with the music playing from the object (radio) with a raycast from my FPS, and and i already have this script:
#pragma strict
Screen.lockCursor = true;
var camera_XX : MouseLook;
var camera_YY : MouseLook;
var Musica: AudioClip;
function Start () {
}
function Update () {
var ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width/2,Screen.height/2));
var hit : RaycastHit;
if (Physics.Raycast (ray, hit, 1000)) {
if(hit.collider.gameObject.tag == "radio")
{
hit.collider.gameObject.audio.Play.("Umacasa");
//"Umacasa" is the name of the music file
}
}
}
but it´s does´t work.
i allready put the file in object audio source.
Can somebody help?
hit.collider.gameObject.audio.Play.(“Umacasa”);
looks like it has an extra dot in it. Try:
hit.collider.gameObject.audio.Play("Umacasa");
shows this error.
Assets/Scripts_Gnosias/Ligar_radio.js(23,49): BCE0023: No appropriate version of ‘UnityEngine.AudioSource.Play’ for the argument list ‘(String)’ was found.
and if it´s works, the sound will be from the object or stay on the environment?
i want it play from the object that i can stepway and the sound stay more far…
tnks for your help.
Finally discover!
#pragma strict
Screen.lockCursor = true;
var camera_XX : MouseLook;
var camera_YY : MouseLook;
var Musica: AudioClip;
function Start () {
}
function Update () {
if (Input.GetMouseButtonUp(1)){
var ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width/2,Screen.height/2));
var hit : RaycastHit;
if (Physics.Raycast (ray, hit, 1000)) {
if(hit.collider.gameObject.tag == "radio")
{
hit.collider.gameObject.audio.Play(1);
}
}
}
}