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 Line · Jul 07, 2010 at 12:39 PM · collisionraycastcollideroncollisionenterplayoneshot

how to PlayOneShot from a OnCollisionEnter wiith a RaycastHit /Collider>Raycast

hello i have this script

var snd : AudioClip; var touch : Vector3; var hit : RaycastHit; var coll : Collision;

function Update () { touch[0] = 320/2; touch[1] = iPhoneInput.GetTouch(0).position.y; touch[2] = 100;

 var ray = Camera.main.ScreenPointToRay (touch);


 if (collider.Raycast (ray, hit, 100)) 
 {
         ??????????coll??????????;
 }

}

function OnCollisionEnter (coll : Collision) {

 audio.PlayOneShot(snd);

}

that i am using to trigger sound from a touch i just dont know what to write in the boolean condition of the ray for the system to understand to start the OnColliderEnter function

i am doing it because if i playoneshot inside my ray condition it will trigger as long as i have my finger over the mesh

i want to be able to trig on enter , like this i touch and it will play , but it will also play if i drag my finger over the other mesh on the screen

thks

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Tetrad · Jul 07, 2010 at 03:05 PM

OnCollisionEnter is for rigidbodies or colliders entering the trigger, not for raycasts.

If you want your sound to only play once, you just need some simple logic to check to see what's going on.

Something like this:

var canPlaySound = false;

function Update() { if( // collider function ) { if( canPlaySound ) {
// play sound canPlaySound = false; } } else { canPlaySound = true; } }

Comment
Add comment · Show 2 · 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 Line · Jul 07, 2010 at 10:29 PM 0
Share

thanks for the quick answer i understand the code i tried it , it is working , but still the sound is looping , so i changed from audio clip to audio source (because i will try to work on the pitch later) i added a !snd.isPlaying condition in the loop then my problem is that the program wait for almost 3 or 4 seconds before it is possible to start the sound again because i have samples with a long reverb on . so i am back to the beginning , i know i cant use the isPlaying boolean funtion i need something like a onEnter collision usable with raycast system , and i have no idea how to do

avatar image Line · Jul 07, 2010 at 10:38 PM 0
Share

because the update fonction is a loop , the condition is going into a loop on everyframe once it plays , once it can t , ...

i have tryed the iPhoneTouchPhase.Began but then i can t drag my finger like i would play strings of a guitar software.

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

No one has followed this question yet.

Related Questions

How can I determine how many colliders exist along a line? 1 Answer

OnCollisionEnter not triggering when two rigidbody collide via Instantiate 1 Answer

raycasts only working with IsTrigger colliders? 1 Answer

Raycast: OnCollisionStay() detect collision not on Ray but Object? 1 Answer

AI Players Movement for Rolling Ball Game 0 Answers


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