Lpoma 6 Report post Posted May 2, 2020 Hola amigos buen día con todos, por favor alguien me puede mandar alguna script c#, donde al pasar el ratón por encima de un objeto 3d este cambie de color y también al hacerle click me permita escoger o cambiar de escena, por favor espero me puedan ayudar muchas gracias de antemano. Antes yo tenia un scrip similar pero era en java y ahora no me acepta en el unity 2019 Share this post Link to post Share on other sites
nomoregames 35 Report post Posted May 2, 2020 Sabias que mediante UI puedes hacer lo que buscas sin necesidad de scripting? Share this post Link to post Share on other sites
pioj 803 Report post Posted May 2, 2020 En el mismo manual de Unity3D , en la sección de UI y de botones hay una muestra clara de cómo cambiar el color del texto. Es una de las opciones por defecto que trae el componente Button de UI... Share this post Link to post Share on other sites
Igor 336 Report post Posted May 2, 2020 pero quiere hacerlo con objetos 3d, no con UI. seria algo asi: -suponiendo que el botos se llama "miBoton01" -tendrias que asignar el rederer del objeto en "boton_01" public Renderer boton_01; void Update() { RaycastHit hit; Ray ray = camera.ScreenPointToRay(Input.mousePosition); boton_01.material.setColor("_Color", new Color(0.5f, 0.5f, 0.5f, 1f));//gris no seleccionado if (Physics.Raycast(ray, out hit)) { if (hit.collider.name == "miBoton01") { boton_01.material.setColor("_Color", new Color(0.5f, 1f, 0.5f, 1f));//verde seleccionado if (Input.GetMouseButtonDown(0)) { //accion del boton } } } } esta sin probar... lo he escrito desde el movil, igual hay algun fallo 2 Share this post Link to post Share on other sites
leocub58 208 Report post Posted May 2, 2020 3 minutes ago, Igor said: pero quiere hacerlo con objetos 3d, no con UI. seria algo asi: -suponiendo que el botos se llama "miBoton01" -tendrias que asignar el rederer del objeto en "boton_01" public Renderer boton_01; void Update() { RaycastHit hit; Ray ray = camera.ScreenPointToRay(Input.mousePosition); boton_01.material.setColor("_Color", new Color(0.5f, 0.5f, 0.5f, 1f));//gris no seleccionado if (Physics.Raycast(ray, out hit)) { if (hit.collider.name == "miBoton01") { boton_01.material.setColor("_Color", new Color(0.5f, 1f, 0.5f, 1f));//verde seleccionado if (Input.GetMouseButtonDown(0)) { //accion del boton } } } } esta sin probar... lo he escrito desde el movil, igual hay algun fallo tiene mérito escribir todo eso desde el móvil xD 1 Share this post Link to post Share on other sites
Igor 336 Report post Posted May 2, 2020 2 hours ago, leocub58 said: tiene mérito escribir todo eso desde el móvil xD si, jeje... cuando iba por la mitad ya me estaba arrepintiendonde no haber contestado con el PC.... jeje Share this post Link to post Share on other sites
Lpoma 6 Report post Posted May 3, 2020 Ahora lo probamos y les cuento mi chas gracias 👍🤗 Share this post Link to post Share on other sites
Lpoma 6 Report post Posted May 4, 2020 Hola amigos solo para comentarles que encontré la solución, si quieren les paso los scrips finales muchas gracias a todos😇 1 Share this post Link to post Share on other sites
davidlopezdev 60 Report post Posted May 5, 2020 (edited) No se si llego tarde pero el propio MonoBehaviour tiene funciones para controlar cuando pinchas o arrastras un objeto, en este caso 3D. Solo tienes que añadirle un collider y te ahorras tener que estar tirando un rayo en el Update y demás. OnMouseDown OnMouseDown is called when the user has pressed the mouse button while over the Collider. OnMouseDrag OnMouseDrag is called when the user has clicked on a Collider and is still holding down the mouse. OnMouseEnter Called when the mouse enters the Collider. OnMouseExit Called when the mouse is not any longer over the Collider. OnMouseOver Called every frame while the mouse is over the Collider. OnMouseUp OnMouseUp is called when the user has released the mouse button. OnMouseUpAsButton OnMouseUpAsButton is only called when the mouse is released over the same Collider as it was pressed. Si decides tirar un rayo, ya que es en el Update guarda en cache y usa Physics.RaycastNonAlloc Edited May 5, 2020 by _davidlopez29 Share this post Link to post Share on other sites
Lpoma 6 Report post Posted May 6, 2020 8 hours ago, _davidlopez29 said: No se si llego tarde pero el propio MonoBehaviour tiene funciones para controlar cuando pinchas o arrastras un objeto, en este caso 3D. Solo tienes que añadirle un collider y te ahorras tener que estar tirando un rayo en el Update y demás. OnMouseDown OnMouseDown is called when the user has pressed the mouse button while over the Collider. OnMouseDrag OnMouseDrag is called when the user has clicked on a Collider and is still holding down the mouse. OnMouseEnter Called when the mouse enters the Collider. OnMouseExit Called when the mouse is not any longer over the Collider. OnMouseOver Called every frame while the mouse is over the Collider. OnMouseUp OnMouseUp is called when the user has released the mouse button. OnMouseUpAsButton OnMouseUpAsButton is only called when the mouse is released over the same Collider as it was pressed. Si decides tirar un rayo, ya que es en el Update guarda en cache y usa Physics.RaycastNonAlloc Quedo de 10 amigos gracias por su apoyo, me llevo por nuevos rumbos y logre el objetivo TNX 1 Share this post Link to post Share on other sites
iRobb 775 Report post Posted May 6, 2020 Qué bonito y vaya cambio! Share this post Link to post Share on other sites
davidlopezdev 60 Report post Posted May 6, 2020 Gran cambio si señor! Buen trabajo! Share this post Link to post Share on other sites
Pistaxo21 19 Report post Posted May 7, 2020 Acabo de verlo, ¡Felicidades! ha quedado espectacular Share this post Link to post Share on other sites