Hello
I'm trying to create an educational AR app for android. I was checking some tutorials on ray casting and i found one for audio but i need one to activate some animations. I have zero developer experience. I just basically started on my dev journey. Does anyone know how to re-purpose this code to activate animations?
Below is the current script i have.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class SoundconVan : MonoBehaviour {
public AudioClip[] aClips; public AudioSource myAudioSource; string btnName;
// Use this for initialization void Start() {
myAudioSource = GetComponent<AudioSource>();
}
// 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 "PlayButton_Van": myAudioSource.clip = aClips[0]; myAudioSource.Play(); break;
case "PauseButton_Van": myAudioSource.clip = aClips[0]; myAudioSource.Pause(); break;
case "StopButton_Van": myAudioSource.clip = aClips[0]; myAudioSource.Stop(); break;
default: break;
} } }
}
}
Thank you in advance.
Just in case anyone else is
Just in case anyone else is looking for something similar, or is having similar problems here is the simple code I ended up with.
Copy to clipboard