Unity 2D Mobile Adventure: Designing an Abstract Class for the Monsters

<p>Today, I was continuing the GameDevHQ 2D Mobile Adventure project, and the goal for today was to design a parent script for the monster objects. This script will cover all monster basic movements and trigger their animations. Then, through inheritance, I&rsquo;ll create scripts for each unique monster so that in the future, I can override certain base functions and add their own unique twist.</p> <h2>Parent Class</h2> <p>For the parent class, I added every property and component that every monster will have. For example, every monster will have a variable for their health, speed, access to their animator, an array of waypoints for movement, and a few other components.</p> <pre> public int Speed { get; private set; } public int Health { get; private set; } public int Gems { get; private set; } protected SpriteRenderer _spriteRenderer; protected bool _moving = true; protected Vector3 _targetPOS; private IMonsterAnim _monsterAnim; [SerializeField] protected Transform[] _wayPoints;</pre> <p>Next, I created an Initilizae method that will be in charge of getting the sprite render and the animator for that specific monster. This is important so we can control the monster&rsquo;s sprite and animations used in the movement method. This is followed by the start method, where the method is called and starts the monster at the first waypoint.</p> <p><a href="https://medium.com/@jdpetta21/unity-2d-mobile-adventure-designing-an-abstract-class-for-the-monsters-bd4e959b9c7d">Read More</a></p>