This site requires JavaScript, please enable it in your browser!
Greenfoot back
Gallier
Gallier wrote ...

2021/5/2

Remove Class from Actor, when isTouching an Object

Gallier Gallier

2021/5/2

#
Hey, Why this command doesn't work? public void hit() { if (isTouching(PilzLvL2.class)) { getWorld().removeObject(PilzLvL2.class); } } I wrote this in the object class fireball... So why this isnt working?
RcCookie RcCookie

2021/5/2

#
You need to specify an instance to remove, not the whole class. You have two options: Replace the statement inside the if block with
getWorld().removeObject(getOneIntersectingObject(PilzLvl2.class));[/code
or, in this case way shorter, remove the whole if statement including the content and add this instead
[code]teloveTouching(PilzLvL2.class);
This method does exactly what the if statement with the code above does.
You need to login to post a reply.