Exemplo n.º 1
0
    void DrawShoot(int index, int dmg)
    {
        StartCoroutine(ShotEffect(index));
        Vector3 realDirection  = fpsCam.transform.forward;
        Vector3 shootDirection = realDirection + new Vector3(
            Random.Range(-0.05f * index, 0.05f * index),
            Random.Range(-0.05f * index, 0.05f * index),
            Random.Range(-0.05f * index, 0.05f * index)
            );
        Vector3    rayOrigin = fpsCam.ViewportToWorldPoint(new Vector3(.5f, .5f, 0));
        RaycastHit hit;

        linesRenderer[index].SetPosition(0, gunEnd.position);
        if (Physics.Raycast(rayOrigin, shootDirection, out hit, weaponRange))
        {
            linesRenderer[index].SetPosition(1, hit.point);
            Shootable shootableComponent = hit.collider.GetComponent <Shootable>();
            if (shootableComponent != null)
            {
                shootableComponent.Damage(dmg);
            }

            BossBehavior boosBehavior = hit.collider.GetComponent <BossBehavior>();
            if (boosBehavior != null)
            {
                boosBehavior.ReceiveDamage(dmg);
            }
        }
        else
        {
            linesRenderer[index].SetPosition(1, rayOrigin + (shootDirection * weaponRange));
        }
    }