Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

690
Views
Unity: haga clic con el mouse en Box Collider

Tengo una pregunta rápida, parece bastante simple, pero no puedo entenderlo. Estoy tratando de hacer clic en una puerta con un clic del mouse que luego se abrirá. Entonces, básicamente, se reproducirá una animación después de hacer clic con el mouse, todo esto ya funciona en mi proyecto, pero desafortunadamente la puerta se abrirá donde sea que haga clic, pero obviamente solo debería abrirse cuando haga clic en la puerta. Hice un colisionador de caja alrededor de la puerta y lo configuré para que se dispare, pero no soluciona mi problema.

¿Alguien podría ayudar? Yo realmente lo apreciaría.

Aquí está mi código actual:

 using System.Collections; using System.Collections.Generic; using UnityEngine; public class ScriptTor : MonoBehaviour { private void Update() { if(Input.GetMouseButtonDown(0)) { GetComponent<Animator>().SetTrigger("Tor"); } } }
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Input.GetMouseButtonDown(0) no verifica si actualmente está haciendo clic en su puerta, y simplemente se dispara cada vez que hace clic cuando se ejecuta el juego (en cualquier lugar de la ventana)

Le sugiero que mire este hilo aquí , lo que implica el uso de Raycasts

over 4 years ago · Santiago Trujillo Report

0

Si tiene una escena en 3D, probablemente necesite usar raycast: intente

 if(Input.GetMouseButtonDown(0)) { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { // Check if hit.transform is door, if(...) GetComponent<Animator>().SetTrigger("Tor"); } }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!