Trail Renderer And ICaptureable implementation

Added a Trail Renderer for the Rope Weapon.

p7

Added another Interface i.e. ICaptureable  for Animals that will be captured through our Rope Weapon. So each animal will be able to give different points to player once they are captured.

We also change the texture of our Rope Projectile to show which animal is captured.

Here is the code of our interface.

public interface ICaptureable

{

    Animal.eAnimalName Capture (GameObject instigator);

}

 

This is in our Rope Projectile Class.

 

 protected override void OnCollideCapture( Collider2D other, ICaptureable capture)

    {

        AnimalName = capture.Capture(gameObject);

        ChangeRopeLoopTexture(AnimalName);

        ReturnToOriginProjectile(true);

        Collider2D myCollider = GetComponent<Collider2D>();

        myCollider.enabled = false;

    }

 

private void ChangeRopeLoopTexture (Animal.eAnimalName animalName)

    {

        // change the texture with animal captured

        switch(animalName)

        {

            case Animal.eAnimalName.Sheep:

            {

                // 

                _ropeLoopRenderer.sprite = SheepCaptured;

                break;

            }

            case Animal.eAnimalName.Ibex:

            {

                // 

                _ropeLoopRenderer.sprite = IbexCaptured;

                break;

            }

            case Animal.eAnimalName.Gazelle:

            {

                // 

                _ropeLoopRenderer.sprite = GazelleCaptured;

                break;

            }

        }

    }

 

Animal Class implements the Icaptureable interface.

Here is the implementation of Icaptureable in animal class

 public Animal.eAnimalName Capture (GameObject instigator)

    {

        if (PointsToGiveToPlayer != 0)

        {

            var projectile = instigator.GetComponent<Projectile>();

            if (projectile != null && projectile.Owner.GetComponent<Player>() != null)

            {

                GameManager.Instance.AddPoints (PointsToGiveToPlayer);

            }

        }

        Destroy (gameObject);

        IsDead = true;

        return _animalName;

    }

 

In our Base Projectile Class, we detect collision and call the OnCollideCapture override as you can see from the code below

 

public virtual void OnTriggerEnter2D (Collider2D other)

    {

        var capture = (ICaptureable) other.GetComponent(typeof (ICaptureable));

        if ( capture != null )

        {

            OnCollideCapture (other, capture);

            return;

        }

        // 

        OnCollideOther(other);

    }

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