Пример #1
0
    void Shoot()
    {
        leftLine.SetPosition(0, left.position);
        rightLine.SetPosition(0, right.position);
        RaycastHit hit;

        if (Physics.Raycast(cockpitCam.transform.position, cockpitCam.transform.forward, out hit))
        {
            leftLine.SetPosition(1, hit.point);
            rightLine.SetPosition(1, hit.point);

            Destroyable target = hit.transform.GetComponent <Destroyable>();
            if (target != null)
            {
                if (target.health > 0.0f)
                {
                    GameObject effect = Instantiate(impact, hit.point, Quaternion.LookRotation(hit.normal));
                    Destroy(effect, 4f);
                    target.TakeDamage(damage);
                }
                else
                {
                    GameObject effect = Instantiate(impact, hit.point, Quaternion.LookRotation(hit.normal));
                    effect.transform.localScale = new Vector3(200, 200, 200);
                    Destroy(effect, 4f);
                    target.Kill();
                    explosion.Play();
                }
            }
            else
            {
                GameObject effect = Instantiate(impact, hit.point, Quaternion.LookRotation(hit.normal));
                Destroy(effect, 4f);
            }
            Debug.Log(hit.transform.name);
        }
        else
        {
            leftLine.SetPosition(1, cockpitCam.transform.position + (cockpitCam.transform.forward * 1000));
            rightLine.SetPosition(1, cockpitCam.transform.position + (cockpitCam.transform.forward * 1000));
        }
    }