Following the interface tutorial from here. There are a number of gameobjects in the scene that implements IDamageable. How do I fire all void Damage(float damage) belonging to gameobjects that implement IDamageable?
I tried the following, but Unity says “Type has to be derived from UnityEngine.Object.”
var damageableObjects = GameObject.FindObjectsOfType(typeof(IDamageable)) as IDamageable[];
foreach(IDamageable d in damageableObjects)
d.Damage(1.0f);
This is just a wild guess, because I haven't worked with Javascript. The tutorial is using C#, but in your code example above you are using javascript, so instead use a c# script and make use of: IDamageable[] damageableObjects = GameObject.FindObjectsOfType(typeof(IDamageable)) as IDamageable[]; foreach(IDamageable d in damageableObjects) d.Damage(1.0f);
– Freaking-PingoOne can also use var in C#, the only thing wrong is the separated foreach statement.
– dmg0600@dmg0600 thanks for picking that up
– ikelaiahfor each, instead offoreach.