i making plataform game and want to make a basic script that will be used to every enemy ,that look like this

if conlisionSensor.positive:   #detect player atack
    timer['time'] = 0 
    own.color = [10,m,m,1]     #make the enemy red 
    own['hp'] += -1            #receive damage

elif time%0.15==0:
    own.color = [1,1,1,1]      #return color to normal
if hp < 1 :

I want to make all children to change colors when the owner receive damage without call each one of then because i want the script to run for each of enemys without modification.

  • $\begingroup$ You enemies are all children of something? Shouldn't they be independent from each other? $\endgroup$ – Monster Feb 22 '17 at 7:23

I'm not sure if I understand you correctly, but you do not need separate code for each object that has the same behavior. You can use the same sensor/controller configuration at each of the objects.

When the enemies are all copies of the same object(s) you can assign them a group and add group instances to the scene.

This way you just configure the original in Blender and all instances receive the changes. This even works with add object when running the game.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.