Ejemplo 1: unidad oncollisionenter2d
void OnCollisionEnter2D(Collision2D col)
{
//This method will run when your 2D game object
//collides with something
Debug.Log("Collided");
}
Ejemplo 2: unidad oncollisionenter
void OnCollisionEnter(Collision col)
{
//This method will run when your game object
//collides with something
Debug.Log("Collided");
}
Ejemplo 3: unidad oncolisionenter
void OnCollisionEnter(Collision collision) {
if (collision.gameObject.tag == "Door")
{
// DoorScript is the name you gave to the script on the door
DoorScript script = collision.gameObject.GetComponent<DoorScript>();
// OpenDoor is a method in your door object's script
script.OpenDoor();
}
}
Ejemplo 4: oncollisionenter2d
using UnityEngine;
using System.Collections;public class ExampleClass : MonoBehaviour {
void OnCollisionEnter2D(Collision2D coll) {
if (coll.gameObject.tag == "Enemy")
coll.gameObject.SendMessage("ApplyDamage", 10);
}
}
Ejemplo 5: oncollisionenter2d
void OnCollisionEnter2D(Collision2D collision) //Make sure to put this out of Voids
{
if (other.gameObject.tag == "Object")
{
Debug.Log ("Collided");
}
}
Ejemplo 6: oncollisionenter2d
OnCollisionEnter2D(Collision2D Collider)
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)