New answers tagged

1

In Javascript, a property can also be a function. Don't make enemyType a string. Make it an object which has multiple methods for different interactions. violetThing = { name: "violet", sprite: "violetThing.png", onTouchFunction: setMagnetic, color: '#ffdd22' } yellowThing = { name: "yellow", sprite: "yellowThing.png", ...


0

There is actually a pseudo official way to use Singleton in Unity. Here is the explanation, basically create a Singleton class and make your scripts inherit from that class.


1

I wrote a singleton class that makes easy to create singleton objects. Its is a MonoBehaviour script, so you can use the Coroutines. Its based on this Unity Wiki article, and I will add option to create it from Prefab later. So you don't need to write the Singleton codes. Just download this Singleton.cs Base Class, add it to your project, and create your ...


0

I would do this rather than have a dozen classes and races; public class GameCharacter { public enum CharacterClass { WARRIOR { @Override public void attack(GameCharacter from, GameCharacter target) { //Do something here } }, MAGE { ...


2

As hinted at in the comments, you'll want to use a combination of Inheritance and Composition. (Inheritance being is a and Composition being has a). In your case, each Character isn't a race or a class, but instead has a race and has a class. Each race would then inherit from a base Race class, and each Class would inherit from a base Class class. An ...



Top 50 recent answers are included