can some one provide me a script?
i want to go to a platform and stay there,, and as soon as i leave the platform .. the platform gets destroyed... i have been trying alot ..and i just dont know how to do it,,,,, im a noob at this,,, and im stuck i used this and some other scripts ,,, but they dont work like i want
.using UnityEngine; using System.Collections;
public class collision : MonoBehaviour {
void OnCollisionEnter2D(Collision2D col)
{
Destroy(GameObject.FindWithTag("Enemy"));
}
}
and some others,,, like on trigger ,, on collider with name tag ,, nd stuff help please....... i want the player to enter the platform (platform name is enemy)(2d) stay as long as he wants,, but as soon as he leaves,, the platform dissapears
Answer by Bigiansen · Aug 19, 2016 at 02:49 AM
The platform needs a script attached that checks for the player collider to enter. Usually you would use 2 colliders for the platform:
-An accurate collider for standing on the platform
-A slightly bigger trigger collider for detecting the collision enter/exit.
The platform script should look like this:
void OnCollisionExit2D(Collider2D col)
{
if(col.Tag == "Player")
{
Destroy(this.gameObject);
}
}
As soon as the player collider stops touching the platform trigger collider, the platform should be destroyed.