Great video, thank you! The code for the future devs: using System.Collections; using System.Collections.Generic; using UnityEngine; public class soundCon : MonoBehaviour { public AudioClip[] aClips; public AudioSource myAudioSource; string btnName; // Use this for initialization void Start () { myAudioSource = GetComponent();
}
// Update is called once per frame void Update () { if (Input.touchCount > 0 && Input.touches[0].phase == TouchPhase.Began) { Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position); RaycastHit Hit; if (Physics.Raycast(ray, out Hit)) { btnName = Hit.transform.name; switch (btnName) { case "myButton1": myAudioSource.clip = aClips[0]; myAudioSource.Play(); break; case "myButton2": myAudioSource.clip = aClips[1]; myAudioSource.Play(); break; case "myButton3": myAudioSource.clip = aClips[2]; myAudioSource.Play(); break; case "myButton4": myAudioSource.clip = aClips[3]; myAudioSource.Play(); break; case "myButton5": myAudioSource.clip = aClips[4]; myAudioSource.Play(); break; case "myButton6": myAudioSource.clip = aClips[5]; myAudioSource.Play(); break; default: break; } } }
For those who is not able to work with this code. You need to add a collider to the object, my suggestion is use the Mesh Collider and enable the Convex.
Thank you for this good video.. Can I add the object and audio in the same scene .. I mean when I but the card will appear the 3D object and audio or video
Could u do the same process also for Area target objects? I wanna creat an AR game and want to add sound and animation script to different objects in my scene where I use vuforia Area targets. If yes how?
Is it possible to make a button press open a URL? I've been trying to figure out how to do this but I can't find any information online regarding this on mobile devices
Hi, I hope you see this, since the vid. Is a bot older How can I code, so that when I click on an object, another Object (my UI panel) opens? + I want to open a different UI panel for each object I click on. Thanks for taking your time :)
Great video. can you help me? how the script is made if when cube is pressed, the object will appear and only focus on that object after cube is pressed
Hi! Can you help me on how to make different objects appear for each side of the Vuforia Multi-Image target? Imagine a multi-target cube, I want to place different objects for each face
Hi can you please explain how to do raycasting with animation? Do I need to put myAnimationSource = GetComponent(); in void Start(), and then call case "object_1": myAnimationSource.Play("animation_001"); break; in this case?
Hi Luke, I was just working on a project that uses the exact code from this example, but with animation instead of sound. yYou are completely correct, however you don't have to get the component in start, as you are just looking for generic hits, and checking for the name of the objects. so, a "public Animator anim;" to begin with to get the animator of the object you want to animate, and then just "case "myButton1": anim.Play("your animation name"); break;"
@@CubicBrain I posted my code below. Unfortunately, it does not work. I have followed your other tutorial for triggering animation with touch only which works great, but it triggers animations for all objects at once. This is why I want to use raycasting to trigger individual animations. Anyways thanks for the help. I really appreciate it. If you see something wrong with the code please tell me. I really want to get this working :D
hi, Your code seem fine. Have you added the animator for the object you want to animate to the script in the inspector? also, make sure that all the names are correct (also capitalization)
@@CubicBrain i.imgur.com/ONXSmTC.png My current script is derived from your other tutorial with touch/keyboard animation but with no raycasting. Would it help if I try to get this working with keyboard input first?
Hi Luke, If you want to hit a specific 3D object on screen (on a touch device) you need to use raycasting. otherwise it wont know where you are clicking. a canvas UI might not need raycasting, but then it would be stuck to your screen.
actually i want make a pop out description in my AR app can anybody help me out with that thing eg when i'll touch on characters head it will give me description about like what is head how many veins that character ahs in that head all that stuff
using System.Collections; using System.Collections.Generic; using UnityEngine; public class clickObject : MonoBehaviour { public GameObject addText;
void Update() { if (Input.GetMouseButtonDown(0)) { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, 100.0f)) { if (hit.transform.gameObject != null) { buttonClicked(hit.transform.gameObject); } } } } public void buttonClicked(GameObject gameObject) {
addText.SetActive(true); // show 3D text } } Sadly it did not work when click on the AR object . Can you help me?
Hi, I am trying to make a virtual button which on click should show me the 3D plane in the Augmented Reality, It seems not be working for me. Someone, please help
How can I make a botón that stops the audio of other buttons and play other audio at same time ? the intention is to avoid that the sounds are not over lapping. tanks for the tutorial.
Hi Josue, you can stop the individual audio sources, or stop all at the same time. the code is just Audio.Stop();, but if you want all to stoop, you have to identify them, stop them, and then play the next. the stop all script could look something like: void StopAllAudio() { allAudioSources = FindObjectsOfType(typeof(AudioSource)) as AudioSource[]; foreach( AudioSource audioS in allAudioSources) { audioS.Stop(); } }
Hi Rosanna, this won't work with mouse click, as it's only registering touch input. You could look at this unity doc for the mouse version: docs.unity3d.com/ScriptReference/Input-mousePosition.html
You might need to add a collider to your model, and match the name og that model to the button name. If that does not work, you can create a cube and make your model a child of that cube. Then just remove the mesh rendere for the cube.
Hi!, thank you so much bro, this video helped me so much but i have a question and i hope you can help me, the sounds that i used are longer so i need to stop them when tracking lost, so if u can help me with that i would apreciate it!
I get very high lag between when I touch a cube and when the sound plays (about a second) also when I press several cubes in quick succession there's audio issues
@@diegoreyes3851 I did, but I honestly can't remember how. I had help from a CS professor from my uni and it was over a year ago :( I don't even have the file anymore
Hello, I have problem with this. I did everything, my scripts it's similar but when I want click nothing play. Can you help me? I have vuforia 7.2.20, when I click on the screen, nothing happens
Hi, I have the same problem with Unity 2018.2.1.7f1 and Vuforia 7.5.26! ARcamera Raycast??? IAm a newbie, where to find this option or asset/Package? I did not find in Unity or Google Thx
Hello, I added the following code in the Update method to enable testing the buttons in the Editor, but apparently it is not possible to click on the buttons when the piano image is recognized and the buttons appear. Is it indeed the case or is there something missing in my code? #if Unity_EDITOR if ( Input.GetMouseButton(0) ) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if ( Physics.Raycast(ray, out hit) ) { _buttonName = hit.transform.name; switch (_buttonName) { case "Button1": _audioSource.clip = _KeysSoundClips[0]; _audioSource.Play(); break; case "Button2": _audioSource.clip = _KeysSoundClips[1]; _audioSource.Play(); break; case "Button3": _audioSource.clip = _KeysSoundClips[2]; _audioSource.Play(); break; default: break; } } } #endif
Hi Joshua. I just tested your code in my project, and it works fine. (I just had to convert the naming to fit my project). Maybe the naming of your buttons is off? In regards to your test code here; This will disregard the "beginning of a mouse press, and just play over and over again if you hold the mouse button pressed (just a note). Here you have a c/p of my code: if (Input.GetMouseButton(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { btnName = hit.transform.name; switch (btnName) { case "myButton1": myAudioSource.clip = aClips[0]; myAudioSource.Play(); Debug.Log("btn1"); break; case "myButton2": myAudioSource.clip = aClips[1]; myAudioSource.Play(); Debug.Log("btn2"); break; case "myButton3": myAudioSource.clip = aClips[2]; myAudioSource.Play(); Debug.Log("btn3"); break; default: break; } } } As you can see my code is the same as yours I just added the debug log so that I would get some feedback in my console.
Thanks for your quick reply. I included the Debug statements and, unsurprisingly, they do not print anything to the console. Let me get something straight: You run the program in editor, put up the image marker, and when the buttons appear on the game view, you try to click on them with the mouse. Right? Or am I doing it wrong when testing it in editor? This is the tutorial that taught me how to process input mouse clicks, so I learned the mouse position input processing from here (ua-cam.com/video/tKX5KRFbGn4/v-deo.html) though the difference of course is that this is a regular Unity program but what I am trying to do is a Vuforia program where the buttons appear when image recognition succeeds and so the buttons move with the image, etc... I would appreciate your thought, so I can get this done. Thanks
Hi Joshua, yes, I have the script attached to the image target, and then I just "scan" the image target with the webcam and click the cubes in the game view with my mouse. Did you check the naming of your buttons?
Yes, I did. It's strange... Do you think "distance" from the webcam might be an issue? I tried it, to no avail. Is there a script somewhere that deals with distance from the image target to the webcam or device cam?
Hi Cubicbrain! I'm trying to do something similar, but opening a url when clicking a 3D object. I'm trying to mix this script with another one (at the end of the comment) seen on another video, but I've been unable till now. You know if there is any tutorial anywhere or, if it's something easy, could you give me a hint? Thank you so much! public class UrlOpener : MonoBehaviour { public string Url; public void Open() { Application.OpenURL(Url); } }
Hi I'm trying this and I have some problem. I use Mapbox instead of Vuforia. Is it can't working? I do with your script, but I touched the objects on screen and it didn't respond. I also use the Debug to check the problem, but it stop at If before. How to solve this problem? Thank you so much.
Hi, i'm not sure how mapbox handles the camera, but the approach should be kind of the same. at it's core it's just the raycasting from the camera that triggers the sound.
i am new to all this , just a quick question , is it possible to create a button in some space / in front of you (not on a specific spot or a picture ) . is it possible please help.
Hi, Yes and no. Vuforia which I use here always needs a marker (picture) to track. this means that it will only function and activate if you have the pre-configured image/picture in front of the camera. if you want to track your surroundings without a marker, you would need ARCore, ARKit, og use Unitys AR foundation. this will track any flat surface.
I made a similar app, and added normal UI buttons which were clickable through the screen. Without Ray Casting. Just normal button. Have you tried that?
First off, these videos are great! I am learning a ton. I do have a question... Can anyone show me how to activate the animator triggers that belong to the other game objects? For example, if I press Button 1, Cube 1's "Roll" trigger is activated, and Cube 2&3's "Jump" triggers are activated.
Hi, Thanks a lot. you can reference the other gameobjects Animator in your script. here is a script that might work for you: public class makeCubeSpin : MonoBehaviour { //reference the specific cube or gameobject in the inspector public Animator cubeAnimator; void Update() { if (Input.GetKeyDown("1")) { //Play the animation clip named "cubeAnimation" cubeAnimator.Play("cubeAnimation"); } } }
Hi Juan, Sure. you just have to play the specific animation in the animator. One of my other videos might help you: ua-cam.com/video/N73EWquTGSY/v-deo.html
Hi there, Is it necessary to have the AudioSource variable as public and then drag & drop the ImageTarget game object onto its public field, so that the AudioSource component can be extracted and assigned to the slot? The AudioSource component is already attached to the ImageTarget game object, so why not just make it private and in the Start method, use GetComponent() in code? Would that not get the AudioSource component?
Hi, strictly speaking no, You don't have to reference the AudioSource. However if the script was/is on another gameobject (like a gameController on an empty GameObject) it would be necessary.
Hi Hana. Then you just have to add the specific call in the switch case. like ex. if you have an animation component, then you could start an animation by writing: anim.Play("spinAnimation").
you can create some simple animations within Unity, but thats primarily position, scale and rotation. external animation applications will be able to do a lot more. regarding loading and triggering the animation, you can watch my Unity trigger animations video (the one with FBX uses externally created animations)
not regarding creating animations in external programs, but the setup and triggering, you can refer to this tutorial: ua-cam.com/video/N73EWquTGSY/v-deo.html
How can an animate an object using these buttons? Here is the code what I've been doing so far. using System.Collections; using System.Collections.Generic; using UnityEngine.SceneManagement; using UnityEngine; public class soundcon : MonoBehaviour { public AudioClip[] aClips; public AudioSource myAudioSource; string btnName; public Animator anim; // Use this for initialization void Start () { myAudioSource = GetComponent (); anim = GetComponent (); } // Update is called once per frame void Update () {
if (Input.touchCount > 0 && Input.touches [0].phase == TouchPhase.Began) { Ray ray = Camera.main.ScreenPointToRay (Input.GetTouch (0).position); RaycastHit Hit; if (Physics.Raycast (ray, out Hit)) { btnName = Hit.transform.name; switch (btnName) { case "myButton1": anim.Play ("point"); myAudioSource.clip = aClips [0]; myAudioSource.Play ();
break; case "myButton2": SceneManager.LoadScene (0); break; default: break; } } } } } Thanks in advance :)
Great video, thank you!
The code for the future devs:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class soundCon : MonoBehaviour {
public AudioClip[] aClips;
public AudioSource myAudioSource;
string btnName;
// Use this for initialization
void Start () {
myAudioSource = GetComponent();
}
// Update is called once per frame
void Update () {
if (Input.touchCount > 0 && Input.touches[0].phase == TouchPhase.Began)
{
Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
RaycastHit Hit;
if (Physics.Raycast(ray, out Hit))
{
btnName = Hit.transform.name;
switch (btnName)
{
case "myButton1":
myAudioSource.clip = aClips[0];
myAudioSource.Play();
break;
case "myButton2":
myAudioSource.clip = aClips[1];
myAudioSource.Play();
break;
case "myButton3":
myAudioSource.clip = aClips[2];
myAudioSource.Play();
break;
case "myButton4":
myAudioSource.clip = aClips[3];
myAudioSource.Play();
break;
case "myButton5":
myAudioSource.clip = aClips[4];
myAudioSource.Play();
break;
case "myButton6":
myAudioSource.clip = aClips[5];
myAudioSource.Play();
break;
default:
break;
}
}
}
}
}
@Matthew Marshall I got scammed : (
This is what I’ve been looking for for hours. OMG. thank you
For those who is not able to work with this code.
You need to add a collider to the object, my suggestion is use the Mesh Collider and enable the Convex.
This helped me alot with a schoolproject.
Thank you!
thank you so much for this tutorial @CubicBrain, it's so detailed but simple and functional as hell. you've really made my day.
Emina Dizdarevic thanks a lot for the great feedback.
This video saved my life, thanks a lot 😭
Exactly what I was needing. Thankyou Very Much!!!!!!
Wow, this is amazing, great work
Thanks a lot. Glad you like it.
Nice video!! Don't forget to remove your Main Camera, otherwise it gives the error that there are 2 audio listeners in the scene.
Thank you very much Sir for this tutorial
Fantastic tutorial video. Thanks so much! ;)
Thanks a lot Paul.
Thank you very much for this tutorial :)
thanks a lot its very helpful for me
Great tutorial! Keep up the good work :)
Thanks a lot.
Thank you
does the button have to be inside the marker? or the markers function for mark only
Thank you!
how about without image tracking or markerless ar?
Great video ! Hi, how to setup using the mouse click?
Hey, can you show something like this, but when you click on the object, a video pops up and starts playing?
Thank you for this good video.. Can I add the object and audio in the same scene .. I mean when I but the card will appear the 3D object and audio or video
It works ;) thanks ;)
However, the OnMouseDown function does the work too
bro? How you does enable the touches with circles? I need to add this touch effects to my AR project. Please help me?
Work ;)
Nice !!!!
Could u do the same process also for Area target objects? I wanna creat an AR game and want to add sound and animation script to different objects in my scene where I use vuforia Area targets. If yes how?
hi can i get help with the android input or raycast mouse input plz
thanks dude,..
I need help sir on how to open links with button click or object tap and dial mobile numbers :/
+1
Is it possible to make a button press open a URL? I've been trying to figure out how to do this but I can't find any information online regarding this on mobile devices
should be possible with: public static void OpenURL(string url). docs.unity3d.com/ScriptReference/Application.OpenURL.html
Hi Sean! Were you able to do it? I'm trying to do just the same as you, but I'm not being able.
Hi, I hope you see this, since the vid. Is a bot older
How can I code, so that when I click on an object, another Object (my UI panel) opens?
+ I want to open a different UI panel for each object I click on.
Thanks for taking your time :)
Why the script not working in unity5? I confuse about calling btnName.
A clips is not showing for me
Great video. can you help me?
how the script is made if when cube is pressed, the object will appear and only focus on that object after cube is pressed
Hi! Can you help me on how to make different objects appear for each side of the Vuforia Multi-Image target? Imagine a multi-target cube, I want to place different objects for each face
Hi can you please explain how to do raycasting with animation?
Do I need to put myAnimationSource = GetComponent(); in void Start(), and then call
case "object_1":
myAnimationSource.Play("animation_001");
break;
in this case?
Hi Luke, I was just working on a project that uses the exact code from this example, but with animation instead of sound. yYou are completely correct, however you don't have to get the component in start, as you are just looking for generic hits, and checking for the name of the objects. so, a "public Animator anim;" to begin with to get the animator of the object you want to animate, and then just "case "myButton1": anim.Play("your animation name"); break;"
@@CubicBrain I posted my code below. Unfortunately, it does not work. I have followed your other tutorial for triggering animation with touch only which works great, but it triggers animations for all objects at once. This is why I want to use raycasting to trigger individual animations. Anyways thanks for the help. I really appreciate it. If you see something wrong with the code please tell me. I really want to get this working :D
hi, Your code seem fine. Have you added the animator for the object you want to animate to the script in the inspector? also, make sure that all the names are correct (also capitalization)
@@CubicBrain i.imgur.com/ONXSmTC.png
My current script is derived from your other tutorial with touch/keyboard animation but with no raycasting. Would it help if I try to get this working with keyboard input first?
Hi Luke, If you want to hit a specific 3D object on screen (on a touch device) you need to use raycasting. otherwise it wont know where you are clicking. a canvas UI might not need raycasting, but then it would be stuck to your screen.
actually i want make a pop out description in my AR app can anybody help me out with that thing eg when i'll touch on characters head it will give me description about like what is head how many veins that character ahs in that head all that stuff
I did all, the output came exactly but audio was not playing we I click the button help me??
I have the same situation when I built it for an iOS device, but it works fine in a Android device. Try Android!
Hey , do you have idea about how to make ar app with groundplane detection for non-arcore devices
Hi, I think AR foundation in Unity might have it. otherwise unitys project mars might work: unity.com/products/unity-mars
hi, if i just want to touch an object to show a text above the object, may i know how to do it? How would the script be like? Can you help me ?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class clickObject : MonoBehaviour
{
public GameObject addText;
void Update()
{
if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, 100.0f))
{
if (hit.transform.gameObject != null)
{
buttonClicked(hit.transform.gameObject);
}
}
}
}
public void buttonClicked(GameObject gameObject)
{
addText.SetActive(true); // show 3D text
}
}
Sadly it did not work when click on the AR object . Can you help me?
@@wuimingleebarroga8629 sorry, how did you do after?
Hi, I am trying to make a virtual button which on click should show me the 3D plane in the Augmented Reality, It seems not be working for me. Someone, please help
How can I make a botón that stops the audio of other buttons and play other audio at same time ? the intention is to avoid that the sounds are not over lapping. tanks for the tutorial.
Hi Josue, you can stop the individual audio sources, or stop all at the same time. the code is just Audio.Stop();, but if you want all to stoop, you have to identify them, stop them, and then play the next. the stop all script could look something like:
void StopAllAudio() {
allAudioSources = FindObjectsOfType(typeof(AudioSource)) as AudioSource[];
foreach( AudioSource audioS in allAudioSources) {
audioS.Stop();
}
}
How do I detect a raycast on a child object?
does it work on iOS
yes it should work.
i can't understand after 7:14, i build it for android phone but it doesn't work. please make detailed video after 7:14. I am beginner in AR.
Hey bro i am also beginner
Why, when I press the cube in play with the mouse, nothing happens? Can someone help me, please?
Hi Rosanna, this won't work with mouse click, as it's only registering touch input. You could look at this unity doc for the mouse version: docs.unity3d.com/ScriptReference/Input-mousePosition.html
@@CubicBrain thank you so much and really great video 👍
can we do this using unity personal?
Yes you can.
i'm having some hiccups T.T mine won't work, but I use a custom made 3D character and I don't know what to do
You might need to add a collider to your model, and match the name og that model to the button name. If that does not work, you can create a cube and make your model a child of that cube. Then just remove the mesh rendere for the cube.
@@CubicBrain thank you. The collider worked
Hi!, thank you so much bro, this video helped me so much but i have a question and i hope you can help me, the sounds that i used are longer so i need to stop them when tracking lost, so if u can help me with that i would apreciate it!
Hi, thanks. You should be able to use the tracking lost function:
private void OnTrackingLost()
{
audio.Stop();}
I get very high lag between when I touch a cube and when the sound plays (about a second) also when I press several cubes in quick succession there's audio issues
do u fix it?
@@diegoreyes3851 I did, but I honestly can't remember how. I had help from a CS professor from my uni and it was over a year ago :( I don't even have the file anymore
Hello, I have problem with this. I did everything, my scripts it's similar but when I want click nothing play. Can you help me? I have vuforia 7.2.20, when I click on the screen, nothing happens
i have the same problem :(, helppppp!
You need add to ARcamera Raycast :) I did this and is ok
Hi, I have the same problem with Unity 2018.2.1.7f1 and Vuforia 7.5.26!
ARcamera Raycast??? IAm a newbie, where to find this option or asset/Package? I did not find in Unity or Google Thx
Hello, I added the following code in the Update method to enable testing the buttons in the Editor, but apparently it is not possible to click on the buttons when the piano image is recognized and the buttons appear. Is it indeed the case or is there something missing in my code?
#if Unity_EDITOR
if ( Input.GetMouseButton(0) )
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if ( Physics.Raycast(ray, out hit) )
{
_buttonName = hit.transform.name;
switch (_buttonName)
{
case "Button1":
_audioSource.clip = _KeysSoundClips[0];
_audioSource.Play();
break;
case "Button2":
_audioSource.clip = _KeysSoundClips[1];
_audioSource.Play();
break;
case "Button3":
_audioSource.clip = _KeysSoundClips[2];
_audioSource.Play();
break;
default:
break;
}
}
}
#endif
Hi Joshua. I just tested your code in my project, and it works fine. (I just had to convert the naming to fit my project). Maybe the naming of your buttons is off? In regards to your test code here; This will disregard the "beginning of a mouse press, and just play over and over again if you hold the mouse button pressed (just a note).
Here you have a c/p of my code:
if (Input.GetMouseButton(0)) {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit)) {
btnName = hit.transform.name;
switch (btnName) {
case "myButton1":
myAudioSource.clip = aClips[0];
myAudioSource.Play();
Debug.Log("btn1");
break;
case "myButton2":
myAudioSource.clip = aClips[1];
myAudioSource.Play();
Debug.Log("btn2");
break;
case "myButton3":
myAudioSource.clip = aClips[2];
myAudioSource.Play();
Debug.Log("btn3");
break;
default: break; }
}
}
As you can see my code is the same as yours I just added the debug log so that I would get some feedback in my console.
Thanks for your quick reply. I included the Debug statements and, unsurprisingly, they do not print anything to the console. Let me get something straight: You run the program in editor, put up the image marker, and when the buttons appear on the game view, you try to click on them with the mouse. Right? Or am I doing it wrong when testing it in editor?
This is the tutorial that taught me how to process input mouse clicks, so I learned the mouse position input processing from here (ua-cam.com/video/tKX5KRFbGn4/v-deo.html) though the difference of course is that this is a regular Unity program but what I am trying to do is a Vuforia program where the buttons appear when image recognition succeeds and so the buttons move with the image, etc... I would appreciate your thought, so I can get this done. Thanks
Hi Joshua, yes, I have the script attached to the image target, and then I just "scan" the image target with the webcam and click the cubes in the game view with my mouse. Did you check the naming of your buttons?
Yes, I did. It's strange... Do you think "distance" from the webcam might be an issue? I tried it, to no avail. Is there a script somewhere that deals with distance from the image target to the webcam or device cam?
Hi! I wonder if is it possible to switch scene whenever I press the button? How can I do that? Thanks
Hi Frances. It should be possible with the scene loader. try something like: SceneManager.LoadScene("OtherSceneName", LoadSceneMode.Additive);
Hi Cubicbrain!
I'm trying to do something similar, but opening a url when clicking a 3D object. I'm trying to mix this script with another one (at the end of the comment) seen on another video, but I've been unable till now. You know if there is any tutorial anywhere or, if it's something easy, could you give me a hint? Thank you so much!
public class UrlOpener : MonoBehaviour
{
public string Url;
public void Open()
{
Application.OpenURL(Url);
}
}
Hi I'm trying this and I have some problem. I use Mapbox instead of Vuforia. Is it can't working?
I do with your script, but I touched the objects on screen and it didn't respond. I also use the Debug to check the problem, but it stop at If before. How to solve this problem?
Thank you so much.
Hi, i'm not sure how mapbox handles the camera, but the approach should be kind of the same. at it's core it's just the raycasting from the camera that triggers the sound.
Hi I built it in IOS and it didn't work. Is it has to build only in Andriod phone?
Hi Pimrumpa. I havn't tried building it to a apple device (as I do not own one). however it should also work on iOS.
Everything was appeared except sound :( Thank you for this dope tutorial tho!
i am new to all this , just a quick question , is it possible to create a button in some space / in front of you (not on a specific spot or a picture ) . is it possible please help.
Hi, Yes and no. Vuforia which I use here always needs a marker (picture) to track. this means that it will only function and activate if you have the pre-configured image/picture in front of the camera. if you want to track your surroundings without a marker, you would need ARCore, ARKit, og use Unitys AR foundation. this will track any flat surface.
Hi does this work with virtual button?
Hi, Yes, but as far as I know virtual buttons are not on screen clickable.
I made a similar app, and added normal UI buttons which were clickable through the screen. Without Ray Casting.
Just normal button.
Have you tried that?
First off, these videos are great! I am learning a ton. I do have a question...
Can anyone show me how to activate the animator triggers that belong to the other game objects? For example, if I press Button 1, Cube 1's "Roll" trigger is activated, and Cube 2&3's "Jump" triggers are activated.
Hi, Thanks a lot. you can reference the other gameobjects Animator in your script. here is a script that might work for you:
public class makeCubeSpin : MonoBehaviour
{
//reference the specific cube or gameobject in the inspector
public Animator cubeAnimator;
void Update()
{
if (Input.GetKeyDown("1"))
{
//Play the animation clip named "cubeAnimation"
cubeAnimator.Play("cubeAnimation");
}
}
}
@@CubicBrain Yes!!! Thank you so much! I'll post the end result once it's ready.
In theory, this should work with ARFoundation? Can anyone answer this.
Hi, Well i should, however I haven't tested it. but the setup is similar.
Is it possible to use this to trigger animations?
Hi Juan, Sure. you just have to play the specific animation in the animator. One of my other videos might help you: ua-cam.com/video/N73EWquTGSY/v-deo.html
CubicBrain thanks. I'll check that out. It's hard being new at being a developer that does not know code hahaha.
sure. let me know if you run into trouble.
CubicBrain thank you very much!
do you have discord by any chance? or better a server in discord?
Hi there, Is it necessary to have the AudioSource variable as public and then drag & drop the ImageTarget game object onto its public field, so that the AudioSource component can be extracted and assigned to the slot? The AudioSource component is already attached to the ImageTarget game object, so why not just make it private and in the Start method, use GetComponent() in code? Would that not get the AudioSource component?
Hi, strictly speaking no, You don't have to reference the AudioSource. However if the script was/is on another gameobject (like a gameController on an empty GameObject) it would be necessary.
Hi! I was wondering how you got the circle touch feedbacks? Was it a script?
Hi Noel. Thats just my screen recorder making those.
0 dislikes damn that s rare
Hi, what if you want to do something other than play a bit of audio, what if I want some text to pop up for example?
Hi Hana. Then you just have to add the specific call in the switch case. like ex. if you have an animation component, then you could start an animation by writing: anim.Play("spinAnimation").
CubicBrain ahh and I'll have to create that animation externally? As in - within the unity environment?
you can create some simple animations within Unity, but thats primarily position, scale and rotation. external animation applications will be able to do a lot more. regarding loading and triggering the animation, you can watch my Unity trigger animations video (the one with FBX uses externally created animations)
I see. do you have any tutorial on something like that that I can refer to? : )
not regarding creating animations in external programs, but the setup and triggering, you can refer to this tutorial: ua-cam.com/video/N73EWquTGSY/v-deo.html
How can an animate an object using these buttons?
Here is the code what I've been doing so far.
using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
using UnityEngine;
public class soundcon : MonoBehaviour {
public AudioClip[] aClips;
public AudioSource myAudioSource;
string btnName;
public Animator anim;
// Use this for initialization
void Start () {
myAudioSource = GetComponent ();
anim = GetComponent ();
}
// Update is called once per frame
void Update () {
if (Input.touchCount > 0 && Input.touches [0].phase == TouchPhase.Began)
{
Ray ray = Camera.main.ScreenPointToRay (Input.GetTouch (0).position);
RaycastHit Hit;
if (Physics.Raycast (ray, out Hit))
{
btnName = Hit.transform.name;
switch (btnName)
{
case "myButton1":
anim.Play ("point");
myAudioSource.clip = aClips [0];
myAudioSource.Play ();
break;
case "myButton2":
SceneManager.LoadScene (0);
break;
default:
break;
}
}
}
}
}
Thanks in advance :)