Exemplo n.º 1
0
    public override void Shoot()
    {
        if (nextShootTime > Time.time)
        {
            return;
        }

        nextShootTime = Time.time + reloadTime;

        Vector3 screenCenter = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width / 2f, Screen.height / 2f, 0));
        int     layerMask    = 1 << 8;
        Vector3 randomPoint;
        Vector3 rayDirection;

        RaycastHit[] hits;
        Ray          ray;

        for (int i = 0; i < numberOfBulletsInACardridge; ++i)
        {
            //create the ray
            randomPoint   = Random.insideUnitSphere * circularSpreadAt1M;
            rayDirection  = Camera.main.transform.forward;
            rayDirection += randomPoint;
            ray           = new Ray(screenCenter, rayDirection);
            //raycast
            hits = Physics.RaycastAll(ray, Mathf.Infinity, layerMask);
            //
            for (int rhi = 0; rhi < hits.Length; ++rhi)
            {
                Wall  wall                     = hits[rhi].collider.gameObject.GetComponent <Wall>();
                float distance                 = hits[rhi].distance;
                float xCurveDropoff            = distance / destructionLvDropoffMaxRange;
                float destructionLvWithDropoff = destructionLevel * destructionLvDropoff.Evaluate(xCurveDropoff);
                wall.AddBulletHole(ray, destructionLvWithDropoff);
            }
        }

        audioSource.Play();
    }