Clean up Weapon

We added a Weapon Class and a Rope class derived from it.

p5

Here is our weapon class

public abstract class Weapon : MonoBehaviour 

{

    public float FireRate;

    public static Transform  ProjectileFireLocation;

    public AudioClip  WeaponShootSound;

    public GameObject FireWeaponEffect;

    protected float     _canFireIn;

}

Here is the Rope Class :

public class Rope : Weapon 

{

    public float MaxRopeLength;

    public float Speed;

    public float ProjectileAngle;

    public RopeProjectile ProjectileRope;

    public Vector2 StartPoint;

    public Vector2 EndPoint;

    public bool IsHit;

    public bool IsMiss;

    public float CurrentRopeLength;

    public Texture2D RopeTrailTexture;

    private Vector2 _velocity;

    private Player _player;

    public enum eCatchableAnimalTypes

    {

        Sheep,

        Ibex,

        Gazelle

    }

    void Start()

    {

        ProjectileFireLocation = WeaponManager.WeaponLocation.transform;

    }

    void Update()

    {

        _canFireIn -= Time.deltaTime;

    }

    public void Fire(GameObject gameObject, Vector2 direction, Vector2 Velocity)

    {

        if (_canFireIn > 0)

            return;

        RopeProjectile projectile = (RopeProjectile) Instantiate (ProjectileRope, ProjectileFireLocation.position, ProjectileFireLocation.rotation);

        projectile.Initialize (gameObject, direction, Velocity);

        ShowFireWeaponEffect();

        //AudioSource.PlayClipAtPoint (WeaponShootSound, transform.position);

        _canFireIn = FireRate;

    }

    private void ShowFireWeaponEffect()

    {

        if (FireWeaponEffect != null)

        {

            var effect = (GameObject)Instantiate (FireWeaponEffect, ProjectileFireLocation.position, ProjectileFireLocation.rotation);

            effect.transform.parent = transform;

        }

    }

    public void TakeDamageFromUncatchableAnimals()

    {

        // give damage to player

    }

    public void MakeRopeTrail()

    {

        // make a trail from start point to end point

        // insert mid points to smooth the rope trail

    }

}

private void FireWeapon()

    {

        Vector2 direction = IsFacingRight ? Vector2.right: –Vector2.right;

        string anmString = “”;

        switch(_equippedWeapon)

        {

            case eEqippedWeapon.Rope:

            {

                // call fire Rope projectile out of rope prefab

                Rope rope = (RopeWeaponManager.WeaponRopePrefab.GetComponent<Rope>();

                rope.Fire(gameObject, direction, _controller.Velocity);

                anmString = “PlayerRopeFire”;

                break;

            }

            case eEqippedWeapon.Shotgun:

            {

                // call fire Shotgun projectile out of Shotgun prefab

                anmString = “PlayerShotgunFire”;

                break;

            }

            case eEqippedWeapon.Rifle:

            {

                // call fire Rifle projectile out of Rifle prefab

                anmString = “PlayerRifleFire”;

                break;

            }

            default:

            {

                // call fire Rope projectile out of rope prefab

                Rope rope = (RopeWeaponManager.WeaponRopePrefab.GetComponent<Rope>();

                rope.Fire(gameObject, direction, _controller.Velocity);

                anmString = “PlayerRopeFire”;

            }

            break;

        }

        //AnimatorInstance.SetTrigger(anmString);

    }

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