- Home /
Destroying Custom Planes
Hi. I just learned about CustomPlanes and am using them for sprites (so that I can properly and easily make billboards) but am now having trouble destroying them. I am using these planes as I said, for sprites which are my enemies. I have a bullet script on my bullets but it does not destroy these planes. Here is the script:
using UnityEngine;
using System.Collections;
public class BulletScript : MonoBehaviour
{
float lifespan = 3.0f;
void Update ()
{
lifespan -= Time.deltaTime;
if (lifespan <= 0)
{
Explode ();
}
}
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Enemy")
{
Destroy (gameObject);
}
}
void Explode ()
{
Destroy (gameObject);
}
}
Any help would be greatly appreciated. Thanks!
Answer by robertbu · Aug 15, 2013 at 03:06 AM
The Wiki CreatePlane script produces the mesh, but unlike the built-in planes, it does not add a collider. Depending on the needs of your game, you need to add either a mesh collider or a box collider to the planes. Select the plane in the hierarchy and use either Component>Physics>Box Collider or Component>Physics>Mesh Collider.
Did that already, should have said (sorry) did not work. (tried both mesh and box....)
Do you bullets hit the collider (i.e. do the bounce off)? Is it a speed problem...if you slow them down, do then then collide? Are you sure you have not set the IsTrigger flag on the colliders? Note either the bullet or the plane needs to have a rigidbody for a collision.
They do not hit - go right through even at incredibly low speeds... yes I am sure about the Trigger, and the bullet prefab has a rigidbody.
...Hmmm... I have no idea what the problem is.
Planes are one sided. Are you hitting the front? You may be using a shader that displays both sides. $$anonymous$$ake sure you try a box collider, since it will register a hit from either side. Turn on Gizmos and verify the collider size and position in Scene view.
I just put a script on the enemy that says if it is hit by a bullet then it gets destroyed. Thanks though and I will still do this but this works for now.