|
Java Code - Collision
[Back]
Code:
//Hold Collider
var collider : Collider;
//Hold 2D Collider
var collider : Collider2D;
function OnCollisionEnter(other : Collision)
{
}
//When you enter the Collision
function OnCollisionExit(other : Collision)
{
}
//When you leave the Collision
function OnCollisionStay(other : Collision)
{
}
//When you stay the Collision
//Put these in the function OnCollision
if(other.gameObject.tag == "Player") {
//This can be any tag you would like it to be, this one is for the "Player" Tag
//So what this do is make it so if the Other Object is a Player it do something
Destroy(gameObject); //Destroy Gameobject
Destroy(other.gameObject); //Destroy Other gameobject
}
//By putting other. you mean the other object that hit into him.
//2D
function OnCollisionEnter2D(other : Collision2D)
{
}
function OnCollisionExit2D(other : Collision2D)
{
}
function OnCollisionStay2D(other : Collision2D)
{
}
function OnCollisionStay2D(other : Collision2D)
{
if(other.gameObject.tag == "Note") {
//Do Something
}
else
{
//Do Something
}
}
//Collider2D Off
collider2D.enabled = false;
//Change Size
//Put in Start, and ect...Not on top
var boxcollider2D = gameObject.GetComponent(BoxCollider2D);
//------------------------
//Change X
boxcollider2D.size.x = 4;
//Change Y
boxcollider2D.size.x = 4;
rigidbody2D.isKinematic = false;
var collider : Collider;
//Hold 2D Collider
var collider : Collider2D;
function OnCollisionEnter(other : Collision)
{
}
//When you enter the Collision
function OnCollisionExit(other : Collision)
{
}
//When you leave the Collision
function OnCollisionStay(other : Collision)
{
}
//When you stay the Collision
//Put these in the function OnCollision
if(other.gameObject.tag == "Player") {
//This can be any tag you would like it to be, this one is for the "Player" Tag
//So what this do is make it so if the Other Object is a Player it do something
Destroy(gameObject); //Destroy Gameobject
Destroy(other.gameObject); //Destroy Other gameobject
}
//By putting other. you mean the other object that hit into him.
//2D
function OnCollisionEnter2D(other : Collision2D)
{
}
function OnCollisionExit2D(other : Collision2D)
{
}
function OnCollisionStay2D(other : Collision2D)
{
}
function OnCollisionStay2D(other : Collision2D)
{
if(other.gameObject.tag == "Note") {
//Do Something
}
else
{
//Do Something
}
}
//Collider2D Off
collider2D.enabled = false;
//Change Size
//Put in Start, and ect...Not on top
var boxcollider2D = gameObject.GetComponent(BoxCollider2D);
//------------------------
//Change X
boxcollider2D.size.x = 4;
//Change Y
boxcollider2D.size.x = 4;
rigidbody2D.isKinematic = false;