00:00
00:00
Newgrounds Background Image Theme

Chan99 just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

i need help cuz im a noob at this..

1,159 Views | 1 Reply
New Topic Respond to this Topic

can some one give me a script ,,,,,,,, for unity 2d csharp ,, i want to go to a platform,,,, and destroy the platform as soon as i leave it,,,,,,,,,,,, i have this script ,,, but it doesnt work.. like i want
using UnityEngine;
using System.Collections;

public class collision : MonoBehaviour
{
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "Enemy")
{
Destroy(other.gameObject);
}
}
}
i want the player to touch the platform ,, and then after you leave the platform ,,,, the platform gets destroyed... pleazzzzzz help. also ,, dont want to get banned for this,, i like the page alot


At 8/19/16 12:58 AM, talitoplays wrote: can some one give me a script ,,,,,,,, for unity 2d csharp ,, i want to go to a platform,,,, and destroy the platform as soon as i leave it,,,,,,,,,,,, i have this script ,,, but it doesnt work.. like i want
i want the player to touch the platform ,, and then after you leave the platform ,,,, the platform gets destroyed... pleazzzzzz help. also ,, dont want to get banned for this,, i like the page alot

Why do you think asking a legit question would you get banned? It won't.

The problem here (I think) is the function you use.
OnTriggerEnter2D works with triggers (pass-through objects with "Is Trigger" option enabled); platforms are generally not triggers (you need to step on them, not fall through). And since you want it to disappear when you exit, you are most likely looking for OnCollisionExit2D function.

Another confusing thing… you want the player to destroy the platform, but the tag you use is Enemy. Wouldn't it be better to use the "Player" tag? Something like this should work, if you tag your Player with "Player" tag and add the script to the platform.

using UnityEngine;
using System.Collections;

public class DestroyOnExit : MonoBehaviour {

 void OnCollisionExit2D (Collision2D coll) {
   // Make sure only Player destroys the platform, not any object
   if (coll.gameObject.tag == "Player") {
     // Destroy the platform
     Destroy(this.gameObject);
   }
 }
}

Here's a picture, just in case.

i need help cuz im a noob at this..