Anamta Khan
Anamta Khan

Reputation: 15

Best Practice Unity, to create different scripts or use switch-cases?

I'm developing a game on unity. Where there are units, with different functionalities but somehow same attributes.

What should i do?

create different script for each kind or make single with switch-cases and functions accordingly ?

What is the best practice to do?

Thanks in advance :)

for example: i have an angry guy and a calm guy, i have one basic inheritance of a person class, but inherited to the same class like unit, but in that i have different switch cases to determine angry , happy , calm and etc. should i make different classes for each of this is the right way to do ?

Upvotes: 0

Views: 367

Answers (1)

Dryadwoods
Dryadwoods

Reputation: 2929

How about using Inheritance? https://msdn.microsoft.com/en-us/library/ms173149.aspx

public abstract class BaseUnit{

   public void virtual DoSomething(){
         // some default code
   }     
}

public class MyUnitType : BaseUnit{
  public override void DoSomething(){
     // my custom code if I do no want the default logic
  }
}

Upvotes: 3

Related Questions