Noticias

¡RECUERDA QUE SI ERES UN NUEVO USUARIO, DEBES PRESENTARTE PARA PODER PUBLICAR MENSAJES! | TENEMOS CANAL OFICIAL DE TELEGRAM: t.me/unity3dspain

Deteccion de colisiones sin "OnTriggerEnter" y "OnColliderEnter"

Iniciado por ArnolRT, Diciembre 27, 2015, 08:30:48 AM

Tema anterior - Siguiente tema
Disculpen quisier saber si existe alguna manera de detectar colisiones pero sin la necesidad de los metodos por defecto, sino por funciones que se puedan introducir en una sentencia if por ejemplo

Existe de dos formas:1)Genérica: Detecta cualquier collider. Las funciones se encuentran dentro de la clase Physics: http://docs.unity3d.com/ScriptReference/Physics.html2)Específica: Detecta un collider en concreto. Las funciones se encuentran dentro de la clase Collider y clases derivadas: http://docs.unity3d.com/ScriptReference/Collider.html 

sera que me lo podrias mostrar en un codigo de ejemplo xfa, no lo entiendo muy bien

Diciembre 27, 2015, 01:08:42 PM #3 Ultima modificación: Enero 01, 1970, 01:00:00 AM por Antonio
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void Update() {
        Vector3 fwd = transform.TransformDirection(Vector3.forward);
        if (Physics.Raycast(transform.position, fwd, 10)) {
            print("¡Hay algo enfrente del objeto!");
        }
    }
}
 
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public Collider coll;
    void Start() {
        coll = GetComponent<Collider>();
    }
    void Update() {
        if (Input.GetMouseButtonDown(0)) {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (coll.Raycast(ray, out hit, 100.0F))
                transform.position = ray.GetPoint(100.0F);
        }
    }
}
 


Etiquetas: