Thanks!! Maybe you want to check my Unity playlist, it contains lots of quick videos solving little problems, here it is: th-cam.com/video/hiA_qRiNgfg/w-d-xo.html
Hey, thanks for this. Is there any way to play sound in 3d, like when the object is in left the Audio will play only in the left channel, same with right.
heey! thank you for watching. With this solution, if you have an AudioSource on your left, it will sound louder on the left channel, same with the right. Did you mean that? If not, let me see if I understand precisely what you want to do. You want an AudioSource to play the sound all the time but only in one of the speakers, left or right, depending on the position of the object relative to the camera. Could that be? If that's the case you could manually override the "stereo pan" variable from the AudioSource, you just need to determine if the object is at the left or at the right of the AudioListener. That could be done with a dot product between the right vector of the AudioListener Transform and another vector calculate from the difference between the position of the AudioSource and the position of the AudioListener, I'll have to check it, but if that dot product is positive, I think it means that the object is at the right of the AudioListener and if it's negative the object is at the left. You could use that information to override the stereo pan variable of the AudioSource. I think I will make a couple videos about it, one on how to know if an object is at the right or at the left from another object; another video on how to manually override the stereo pan variable and a third video with the practical example.
nice, then let me extend a little bit the solution. Inside an active script you could define two variables, an AudioSource variable and a Transform variable: public AudioSource myAudioSource; public Transform myAudioListener; In the inspector drag the GameObject with the AudioSource in the first variable and the GameObject with the AudioListener in the second variable. Then in Update you make the dot product and override the stereopan variable: void Update(){ Vector3 v = myAudioSource.transform.position - myAudioListener.position; float dotProduct = Vector3.Dot(myAudioListener.right,v); if(dotProduct>0){ myAudioSource.panStereo = 1f; }else{ myAudioSource.panStereo = -1f; } } I think that should work but maybe there is a syntax error
@@GameDevTraumEN Damn, you made my work easier. I don't know how to thank you, no TH-camr had answered me in the way you have. Delighted to be your subscriber. All the very best with your Channel, thanks again 👍
Thank you for watching! I want to produce more content in 2024, solving lots of problems and doing experiments. I think my english is improving, I don't know if I'll be able to make a live stream but that would be awesome too. Happy new year!
You sent me the link to this in a comment on one of your other videos. I gotta be honest. I'm not going to watch this right now. I don't need it. I will leave a suggestion for a new video though. There's plenty of videos on how to make a button to switch scenes and plenty on how to add a sound to a button when it is pressed. There is no video on how to do both at the same time. That would make a great video. I'm not sure how you'd tag it to make the TH-cam and Google algorithms see it, but I know it's a thing that people want.
It's a problem very specific and you could solve it in many different ways, here's one possible solution: Make the button play sound when pressed, like in this video: th-cam.com/video/TSBzmaZmEgU/w-d-xo.html Inside a script (choose a meaningful one, like a GameController or some script that you remember that you add the function to change to another scene) define two functions, a function that the button will call and another function to load the scene which should be called a couple seconds later, something like this: public void Button_ChangeScene(){ //this function will be called by the button but doesn't change the scene immediately } void LoadScene(){ //This function changes the scene //SceneManager.LoadScene.... } Connect the same button that plays the sound to the Button_ChangeScene function, you need to hit the plus sign one more time in the OnClick event of the button so that the button make two things when pressed. You can see how to connect a button to a function of a script in the following video: th-cam.com/video/dZ8I73erDSk/w-d-xo.html The previous video also show how to load a scene. Inside the Button_ChangeScene Invoke the LoadScene function with a delay, for example 1 second, the result will be something like this: public void Button_ChangeScene(){ Invoke("LoadScene",1f); } For more about calling function with delay check this other video: th-cam.com/video/2dcFOVS-rYM/w-d-xo.html That should work, I would also disable the button when pressed so you can't press it again. I don't have a video about it but is a similar to the first video on how to play sound when pressing a button, you add a third function in the OnClick event of the button, drag the GameObject of the button and then you can choose the "SetActive" function inside GameObject and uncheck the checkbox, that will turn the button off when pressing it. You could also look for the "Interactable" parameter inside Button (in the dropdown menu where you choose what the button will do), in that case you also uncheck the checkbox and the result is that the button becomes noninteractive when you press it but it will be still visible.
@@GameDevTraumEN good lord. I didn't expect that lengthy of a reply. I'll be back tomorrow to read and test it. Regardless, thank you. Whether the rest of the videos apply to be or not, I'll be watching them.
It's a long text but the idea is simple: -The button play sound by its own -The button also call a function inside a script, which Invoke a load function with a certain delay -The Load function finally changes the scene -Optional: Disable the button when pressed
*My Unity repository* 👉 github.com/GameDevTraum/GDT-Solutions-for-Unity
*Complete Unity PLAYLIST:* th-cam.com/video/O6uvrwp1Gj4/w-d-xo.html
zepic
Great video man - straight and to the point!
Thanks!!
Maybe you want to check my Unity playlist, it contains lots of quick videos solving little problems, here it is:
th-cam.com/video/hiA_qRiNgfg/w-d-xo.html
Great video, straight to the point, exacly what I was looking for
Hey, thanks for this.
Is there any way to play sound in 3d, like when the object is in left the Audio will play only in the left channel, same with right.
heey! thank you for watching.
With this solution, if you have an AudioSource on your left, it will sound louder on the left channel, same with the right. Did you mean that?
If not, let me see if I understand precisely what you want to do.
You want an AudioSource to play the sound all the time but only in one of the speakers, left or right, depending on the position of the object relative to the camera. Could that be?
If that's the case you could manually override the "stereo pan" variable from the AudioSource, you just need to determine if the object is at the left or at the right of the AudioListener. That could be done with a dot product between the right vector of the AudioListener Transform and another vector calculate from the difference between the position of the AudioSource and the position of the AudioListener, I'll have to check it, but if that dot product is positive, I think it means that the object is at the right of the AudioListener and if it's negative the object is at the left. You could use that information to override the stereo pan variable of the AudioSource.
I think I will make a couple videos about it, one on how to know if an object is at the right or at the left from another object; another video on how to manually override the stereo pan variable and a third video with the practical example.
@@GameDevTraumEN Yes, this was my question and Wow! Thanks for this detailed solution, I'll try to implement this.
nice, then let me extend a little bit the solution.
Inside an active script you could define two variables, an AudioSource variable and a Transform variable:
public AudioSource myAudioSource;
public Transform myAudioListener;
In the inspector drag the GameObject with the AudioSource in the first variable and the GameObject with the AudioListener in the second variable.
Then in Update you make the dot product and override the stereopan variable:
void Update(){
Vector3 v = myAudioSource.transform.position - myAudioListener.position;
float dotProduct = Vector3.Dot(myAudioListener.right,v);
if(dotProduct>0){
myAudioSource.panStereo = 1f;
}else{
myAudioSource.panStereo = -1f;
}
}
I think that should work but maybe there is a syntax error
@@GameDevTraumEN Damn, you made my work easier. I don't know how to thank you, no TH-camr had answered me in the way you have. Delighted to be your subscriber. All the very best with your Channel, thanks again 👍
Thank you for watching!
I want to produce more content in 2024, solving lots of problems and doing experiments.
I think my english is improving, I don't know if I'll be able to make a live stream but that would be awesome too.
Happy new year!
Eres de Murcia. Lo se
thank for helping : )
You sent me the link to this in a comment on one of your other videos.
I gotta be honest. I'm not going to watch this right now. I don't need it.
I will leave a suggestion for a new video though.
There's plenty of videos on how to make a button to switch scenes and plenty on how to add a sound to a button when it is pressed.
There is no video on how to do both at the same time. That would make a great video. I'm not sure how you'd tag it to make the TH-cam and Google algorithms see it, but I know it's a thing that people want.
It's a problem very specific and you could solve it in many different ways, here's one possible solution:
Make the button play sound when pressed, like in this video:
th-cam.com/video/TSBzmaZmEgU/w-d-xo.html
Inside a script (choose a meaningful one, like a GameController or some script that you remember that you add the function to change to another scene) define two functions, a function that the button will call and another function to load the scene which should be called a couple seconds later, something like this:
public void Button_ChangeScene(){
//this function will be called by the button but doesn't change the scene immediately
}
void LoadScene(){
//This function changes the scene
//SceneManager.LoadScene....
}
Connect the same button that plays the sound to the Button_ChangeScene function, you need to hit the plus sign one more time in the OnClick event of the button so that the button make two things when pressed. You can see how to connect a button to a function of a script in the following video:
th-cam.com/video/dZ8I73erDSk/w-d-xo.html
The previous video also show how to load a scene.
Inside the Button_ChangeScene Invoke the LoadScene function with a delay, for example 1 second, the result will be something like this:
public void Button_ChangeScene(){
Invoke("LoadScene",1f);
}
For more about calling function with delay check this other video:
th-cam.com/video/2dcFOVS-rYM/w-d-xo.html
That should work, I would also disable the button when pressed so you can't press it again.
I don't have a video about it but is a similar to the first video on how to play sound when pressing a button, you add a third function in the OnClick event of the button, drag the GameObject of the button and then you can choose the "SetActive" function inside GameObject and uncheck the checkbox, that will turn the button off when pressing it.
You could also look for the "Interactable" parameter inside Button (in the dropdown menu where you choose what the button will do), in that case you also uncheck the checkbox and the result is that the button becomes noninteractive when you press it but it will be still visible.
@@GameDevTraumEN good lord. I didn't expect that lengthy of a reply. I'll be back tomorrow to read and test it.
Regardless, thank you. Whether the rest of the videos apply to be or not, I'll be watching them.
It's a long text but the idea is simple:
-The button play sound by its own
-The button also call a function inside a script, which Invoke a load function with a certain delay
-The Load function finally changes the scene
-Optional: Disable the button when pressed
THX