using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public interface IShootable
{
float nextAttack { get; }
float shootRange { get; }
Transform Transform { get; }
float Damage { get; }
LayerMask LayerToDamage { get; }
DamageType DamageType { get; }
Action Shoot { get; set; }
Action ShootType { get; set; }
public void AssignWeaponType(FireType firetype, AmmoType ammotype)
{
if (firetype is FireType.Single) Shoot = SingleFire;
else if (firetype is FireType.Auto) Shoot = AutoFire;
if (ammotype is AmmoType.Raycast) ShootType = RaycastAmmo;
}
void ShootWeapon()
{
Shoot();
}
void SingleFire()
{
if (Input.GetMouseButtonDown(0))
{
if (Time.time > nextAttack)
{
ShootType();
}
}
}
void AutoFire()
{
if (Input.GetMouseButton(0))
{
if (Time.time > nextAttack)
{
ShootType();
}
}
}
protected virtual void RaycastAmmo()
{
RaycastHit hit;
if (Physics.Raycast(Transform.position, Transform.TransformDirection(Vector3.forward), out hit, shootRange))
{
if ((LayerToDamage.value & (1 << hit.transform.gameObject.layer)) > 0)
{
hit.collider.GetComponent<IDamageable>().ApplyDamage(Damage, DamageType);
}
}
}
}
Example of my current interface, but Interface can't instantiate an object so i'm not sure how to add that, and charge function requires coroutine which it cant handle either