- Home /
how to make the character look at the object and when clicked on mouse0 the object is removed with sound?(3D)
how to make the character look at the object and when clicked on mouse0 the object is removed with sound? 3D
Comment
Best Answer
Answer by samu1904 · Mar 06, 2021 at 03:55 PM
I didn't have much time to test it but i think this might give you an idea were to continue, there are some improvements you can make to the code.
public AudioClip audio;
void Update()
{
RaycastHit hit;
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);//Detect the position of the mouse, the center of the screen
if (Physics.Raycast(ray, out hit))//generate the ray
{
if (Input.GetMouseButtonDown(0))
{
Destroy(hit.collider.gameObject);//Destroy the object the ray hit
AudioSource.PlayClipAtPoint(audio, transform.position); //PLAYS THE SOUND
}
}
}
Your answer
Follow this Question
Related Questions
Play sound on button press? 1 Answer
How To play sound with a keypress 2 Answers
Background music and button sound at the same time PROBLEM 1 Answer