Esempio n. 1
0
    private void Shoot()
    {
        Vector3 placeExpl = new Vector3();

        StartCoroutine(ShowShoot());
        Ray ray = new Ray(shootAncor.position, shootAncor.forward);

        RaycastHit[] raycastHits = Physics.SphereCastAll(ray, radiusOFShoot, maxDistanceOfShoot, shootLayerMask);
        foreach (RaycastHit hit in raycastHits)
        {
            EnemyControl curEnemyControl = hit.collider.GetComponent <EnemyControl>();
            if (curEnemyControl)
            {
                if (placeExpl == default)
                {
                    placeExpl = hit.collider.transform.position;
                }

                curEnemyControl.DestroyObj();

                gameBuilder.IncreaseEnemyHealth();
            }
        }
        if (placeExpl != Vector3.zero)
        {
            exposion.SetActive(true);
            exposion.transform.position = placeExpl;
            //exposion.transform.position = transform.position;
            exposion.transform.rotation = transform.rotation;
            pSexposion.Play();
            StartCoroutine(StopExplotion());
        }

        //Debug.DrawRay(shootAncor.position, shootAncor.forward * maxDistanceOfShoot, Color.red, 1000f);
    }