Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by BarberaTp · Oct 15, 2013 at 02:49 PM · raycastaudioaudioplay

How can i switch on music on a Radio (object)?

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

creen.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?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mattssonon · Oct 15, 2013 at 02:52 PM 1
Share

Please format your code properly by using the button with the 1's and 0's in its icon. And what do you mean, it doesn't work? How much of the code is executed?

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by tanoshimi · Oct 15, 2013 at 03:00 PM

 hit.collider.gameObject.audio.Play.("Umacasa");

looks like it has an extra dot in it. Try:

 hit.collider.gameObject.audio.Play("Umacasa");
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by BarberaTp · Oct 15, 2013 at 04:35 PM

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mattssonon · Oct 16, 2013 at 07:29 AM 1
Share

Please don't post comments as answers, ins$$anonymous$$d use the Add new comment button to reply to someone else's comment.

avatar image
0

Answer by BarberaTp · Oct 15, 2013 at 04:24 PM

Finally discover!

pragma strict

creen.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);
            
            
            }
      }
  }


}

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mattssonon · Oct 16, 2013 at 07:30 AM 1
Share

Please accept the answer as the right one, so the question is categorized as solved for other visitors.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Change Pitch on Collision 1 Answer

Boolean and audio is not working right 1 Answer

How to play music/audio 2 Answers

Play back multi channel audio 0 Answers

Playing audio brings this error: An invalid seek position was passed to this function. Does anyone knows what does this mean? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges