Every active Object a Script? no some efficient way?

I have 5 Objects Patrolling same, but in various directions . the simple way is to create 5 different scripts and attach them one by one to objects. I mean 5 different script for just a simple difference in direction ? seems annoying.

is there an easier, Efficinet way to make 1 script and customize it for specific objects?

something like Inheritence in class programming ?

and another question. where i should define a public class, to derive from it in scripts ?
in another script ?

5 different script for just a simple
difference in direction ? seems


Hi, I’m not too sure how new you are, but I believe what you are looking for is an array… So whichever object you are using to apply the script, you should look in to your script and change the var, as an example:

public var Patrols : GameObject; //This allows an array, check the inspector to apply them

public var Patrols : GameObject; //This is not an array, and is just an individual Game Object.

Let me know if this helps.

Multiple solutions

  1. Use variables. You can use a public bool that is checked before each action to determine weather to take it or not. Set the bool via an inspector or another script
  2. Use inheritance. Both JavaScript and C# support regular inheritance. Anything that inherits from MonoBehavior can be attached as a component, even if there are several other inheritance layers in between
  3. Separate it out into different scripts and attach each one as a separate component
  4. Write completely different scripts for each object

I think you are not understanding what people are telling you

The proper unity solution is public fields. Every public field gets exposed in the Inspector and can be set differently
for every different instance of that component on an object. For instance you could have

public int direction;

Where 0= north, 1 = east, etc…

Or velocities for movement in X and Y.
(Which RigidBody already exposes for you)

Or anything else you want to set per object.