Unity 3D destroy Game Object On Collide

Опубликовано: 16 Октябрь 2024
на канале: Dubravko Miter
13,638
12

Making free platform game ! One man show
---------------------------------------­­---------------------------------------­-­---------------------------------------------------
Javascrip: GOOD 4 2D GAMES AND 3D GAMES ! VERSION 1 DESTROY ANY OBJECT
---------------------------------------­­---------------------------------------­-­---------------------------------------------------

function OnTriggerEnter( collider : Collider )
{
Destroy(collider.gameObject);
}










---------------------------------------------------------------------------------------------------------------------------------------------------
BONUS SCRIPT NOT IN THIS VIDEO VERSION 2 DESTROY SPECIFIC OBJECT JAVA SCRIPT :
---------------------------------------------------------------------------------------------------------------------------------------------------

#pragma strict

function OnCollisionEnter (col : Collision)
{
if(col.gameObject.name == "NAME OFF YOUR OBJECT HERE ENTER OBJECT TAG NAME")
{
Destroy(col.gameObject);
}
}








---------------------------------------------------------------------------------------------------------------------------------------------------
BONUS SCRIPT NOT IN THIS VIDEO VERSION 3 DESTROY OBJECT on Player trigger Enter
---------------------------------------------------------------------------------------------------------------------------------------------------

function OnTriggerEnter (player : Collider) {
if(player.gameObject.tag=="Player") {
Destroy(this.gameObject);
}
}






---------------------------------------------------------------------------------------------------------------------------------------------------
C# SCRIPT VERSION NOT IN THIS VIDEO VERSION 4 DESTROY SPECIFIC OBJECT :
---------------------------------------------------------------------------------------------------------------------------------------------------



using UnityEngine;
using System.Collections;

public class DestroyCubes : MonoBehaviour
{
void OnCollisionEnter (Collision col)
{
if(col.gameObject.name == "prop_powerCube")
{
Destroy(col.gameObject);
}
}
}







---------------------------------------------------------------------------------

Copyright Free Music in this video by:

Song: Virtual Riot - Energy Drink
» Download:
http://bit.ly/RebornDownload

Creative Commons License
http://creativecommons.org/licenses/b...

--------------------------------------

Artist's Links:
Virtual Riot - Energy Drink

  / virtualriotmusic  
  / virtual-riot