示例#1
0
    public GameObject Shoot(float fireRate, GameObject from, float damage)
    {
        if (Ammo > 0)
        {
            Ammo--;
            RaycastHit hit;
            Ray        shootRay = new Ray(transform.position, -transform.forward);
            if (Physics.Raycast(shootRay, out hit, 500, shootableMask))
            {
                lineRenderer.SetPosition(0, shootPoint.position);

                lineRenderer.SetPosition(1, new Vector3(hit.point.x, shootPoint.position.y, hit.point.z));
                StartCoroutine(FireEffect(fireRate));

                MonoBehaviour[] mono = hit.collider.gameObject.GetComponents <MonoBehaviour>();
                foreach (MonoBehaviour m in mono)
                {
                    if (m is IShootable)
                    {
                        IShootable shootable = (IShootable)m;
                        shootable.OnGetShot(from, damage);
                    }
                }

                return(hit.collider.gameObject);
            }
        }

        return(null);
    }