Adding Villain for the first time

posted in: Daily Progress | 0

So today I added the main villain AKA Wildebeest in the game.

I am working with a placeholder texture for it. Please do not mind. Of course we will add cool texture and animation to our villain.

I Also Added the health bar function i.e. 10 out of 100 is decreased every time wildebeast hits the horse.


Here is the code I was working on.

public class Wildebeast : Animal 


    public Animator WildebeastAnimator;

    public float DestroyInDistance;

    private Vector2 _direction;

    private Player  _player;

    public void Start()


        _player = GameObject.FindWithTag(“Player”).GetComponent<Player>();

        _animalName = Animal.AnimalName.Wildebeest;

        _animalKind = Animal.AnimalKind.Herbivore;

        SetSpeed(Random.Range(StartSpeed, MaxSpeed) );


    public void Update()


        float distance = _player.transform.position.x – transform.position.x;

        if ( Mathf.Abs(distance) > DestroyInDistance )




        if (LevelManager.DifficultyLevel > 5)


            SetSpeed(Random.Range( MaxSpeed,  MaxSpeed + LevelManager.DifficultyLevel));




    public void DestroyMe ()


        // signal AI manager to destroy this



    public void AIUpdate()




    public void SetSpeed( float speed)


        CurrentSpeed = speed;



And for the Health function, I have to implement an interface function for taking damage

This code went into the our Player class

public void TakeDamage (int damage, GameObject instigator)


        Health -= damage;

        if (Health <= 0)


        // blinking is true, disable player collider for x time


        _bHit = true;


    public void ChangePlayerLayerMask(bool Reset = false)


        if (Reset)

            _controller.PlatformLayerMask = _oldLayerMask;


            _controller.PlatformLayerMask.value = 0;


ChangePlayerLayerMask() changes the Layer mask to nothing. It was set to wildebeast in start

We have to call this in the update method

        // handle takedamage timer

        if ( _bHit && (_takeDamageCoolDownTime -= Time.deltaTime) <= 0 )


            // reset layer mask


            _bHit = false;

            _takeDamageCoolDownTime = TakeDamageCoolDownTime;


You can always ask me if you need any help.

I will post a video log at the end of this week.

Thanks for reading.

if you want to check out some of our projects please subscribe to our YouTube channel:

You can check up our work in progress games here:

If you are looking for solutions to game development issues see our blogs here:

If you like our projects please sign up for our newsletter at the bottom of this Page.

Leave a Reply