ShotBy() public method

public ShotBy ( GameObject go, Vector3 location, int damage ) : void
go GameObject
location Vector3
damage int
return void
Exemplo n.º 1
0
    IEnumerator Fire(Ray ray)
    {
        if (m_firing || (m_hasFired && !m_isAutomatic) || m_reloading || !HasAmmo())
        {
            return(false);
        }
        m_firing   = true;
        m_hasFired = true;
        DecrementAmmo();
        RaycastHit rh;
        Vector3    dest;
        Shootable  target = null;

        Physics.Raycast(ray, out rh, float.MaxValue);
        if (rh.collider != null)
        {
            dest   = rh.point;
            target = rh.collider.gameObject.GetComponent <Shootable>();
        }
        else
        {
            dest = ray.origin + 1000 * ray.direction;
        }
        var bullet = (GameObject)GameObject.Instantiate(m_bulletPrefab);
        var lr     = bullet.GetComponent <LineRenderer>();

        bullet.transform.parent        = m_muzzleExit;
        bullet.transform.localPosition = Vector3.zero;
        bullet.transform.localRotation = Quaternion.identity;
        lr.SetPosition(1, bullet.transform.InverseTransformPoint(dest));
        lr.SetVertexCount(2);
        m_audio.Play();

        yield return(new WaitForSeconds(0.1f));

        if (target != null)
        {
            target.ShotBy(m_player == null ? gameObject : m_player.gameObject, rh.point, m_damage);
        }

        Destroy(bullet);

        if (m_shotDelay > 0)
        {
            yield return(new WaitForSeconds(m_shotDelay));
        }

        m_firing = false;
    }