Recabamos en el mundo on line para mostrarte la solución para tu dilema, en caso de alguna duda déjanos tu inquietud y respondemos porque estamos para servirte.
Ejemplo 1: unidad raycast
RaycastHit hit;// Does the ray intersect any objects excluding the player layerif(Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward),out hit, Mathf.Infinity, layerMask))
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward)* hit.distance, Color.yellow);
Debug.Log("Hit");else
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward)*1000, Color.white);
Debug.Log("No Hit");
Ejemplo 2: unidad raycast
voidUpdate()// Bit shift the index of the layer (8) to get a bit maskint layerMask =1<<8;// This would cast rays only against colliders in layer 8.// But instead we want to collide against everything except layer 8. The ~ operator does this, it inverts a bitmask.
layerMask =~layerMask;RaycastHit hit;// Does the ray intersect any objects excluding the player layerif(Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward),out hit, Mathf.Infinity, layerMask))
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward)* hit.distance, Color.yellow);
Debug.Log("Did Hit");else
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward)*1000, Color.white);
Debug.Log("Did not Hit");
Ejemplo 3: cómo hacer una unidad raycast
usingUnityEngine;// C# example.publicclassExampleClass:MonoBehaviourvoidUpdate()// Bit shift the index of the layer (8) to get a bit maskint layerMask =1<<8;// This would cast rays only against colliders in layer 8.// But instead we want to collide against everything except layer 8. The ~ operator does this, it inverts a bitmask.
layerMask =~layerMask;RaycastHit hit;// Does the ray intersect any objects excluding the player layerif(Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward),out hit, Mathf.Infinity, layerMask))
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward)* hit.distance, Color.yellow);
Debug.Log("Did Hit");else
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward)*1000, Color.white);
Debug.Log("Did not Hit");
This example creates a simple Raycast, projecting forwards from the position of the object's current position, extending for10 units.usingUnityEngine;publicclassExampleClass:MonoBehaviourvoidFixedUpdate()Vector3 fwd = transform.TransformDirection(Vector3.forward);if(Physics.Raycast(transform.position, fwd,10))print("There is something in front of the object!");
Ejemplo 4: raycasting en unidad
RaycastHit hit;// Does the ray intersect any objects excluding the player layerif(Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward),out hit, Mathf.Infinity, layerMask))
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward)* hit.distance, Color.yellow);
Debug.Log("Did Hit");
Ejemplo 5: unity3d raycast
usingUnityEngine;// C# example.publicclassExampleClass:MonoBehaviourvoidUpdate()// Bit shift the index of the layer (8) to get a bit maskint layerMask =1<<8;// This would cast rays only against colliders in layer 8.// But instead we want to collide against everything except layer 8. The ~ operator does this, it inverts a bitmask.
layerMask =~layerMask;RaycastHit hit;// Does the ray intersect any objects excluding the player layerif(Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward),out hit, Mathf.Infinity, layerMask))
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward)* hit.distance, Color.yellow);
Debug.Log("Did Hit");else
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward)*1000, Color.white);
Debug.Log("Did not Hit");
Aquí puedes ver las reseñas y valoraciones de los lectores
Si tienes algún duda y forma de aumentar nuestro tutorial eres capaz de realizar una ilustración y con mucho gusto lo leeremos.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)