i try to get animated voice when i touch my object (animal), i try this code, it run correctly when i use a cube object from unity, but when i try this code with 3D object that i downloaded , i dont get the voice.
script.
/****/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Sound : MonoBehaviour
{
public AudioClip aClips;
public AudioSource MyAudio;
string Animal;
// Start is called before the first frame update
void Start()
{
MyAudio = 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);
//Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit Hit;
if(Physics.Raycast(ray, out Hit))
{
Animal = Hit.transform.name;
switch (Animal)
{
case "a1":
MyAudio.clip = aClips[0];
MyAudio.Play();
break;
case "a2":
MyAudio.clip = aClips[1];
MyAudio.Play();
break;
case "a3":
MyAudio.clip = aClips[2];
MyAudio.Play();
break;
/*case "Lion":
MyAudio.clip = aClips[0];
MyAudio.Play();
break;*/
default:
print("0000");
break;
}
}
}
}
}