Hello Everyone.
Im making a 2d Spaceshooter game but i have problem at Destory object by collider.
I want my “laser” will be destroy the enemy. but any code that im using aren’t working.
my laser and player tick on “is trigger”.
what code do i need to use and what to do with the rigidbody. ?
Thanks
A bit difficult to understand - but if you have a “laser” object with a collider set to “is trigger” intersect with another collider (like the enemy) that has a rigidbody attached, then implementing an OnTriggerEnter method in a script attached to your laser should end up getting called with the Collider other parameter set to whatever the laser has collided with. So you’d just have to determine if the other collider is something your laser should destroy (like the enemy) and call Destroy(other.gameObject) and bloop - enemy gone.
Or bleep, depending where you’re from.
Thanks for reply, but i dont realy understand what i have to do…
https://www.youtube.com/watch?v=rldjLcOTmzY = this is the video that i using for the game…
i used everything on there and its not working…
(im using c#)…
thanks
Ok, let’s see… verify that your “enemy” and “laser” objects have Rigidbody components attached. If they don’t, then with the object selected click on the Component > Physics > Rigidbody option in the menu to add it. It looks like you’ll have to untick the ‘Use Gravity’ option and tick ‘Is Kinematic’ on the Rigidbody components for both.
Verify that your Enemy.cs script has an OnTriggerEnter method that looks like this:
void OnTriggerEnter(Collider other)
{
if(other.CompareTag("Lazer"))
{
Destroy(gameObject);
}
}
And finally, make sure that your “laser” object is actually tagged as what you’re passing in to CompareTag - in this case, “Lazer”. Select the “laser” object and look at the top of the inspector (right underneath the name of the object) for the Tag dropdown - if it doesn’t have “Lazer” selected, then you need to click the Add Tag… option and enter it like so:
Then select your new “Lazer” tag for your “laser” object and… that should be it.
Cool?
finally its work !!! thanks so much you realy helped!!
so much time im working on it ! thanks! ! !
Awesome!
Good luck with the rest of the tutorials and have a barrel-full-of-monkeys of fun!