Пример #1
0
    public void Shoot()
    {
        float shotDistance = range;

        if (CanShoot())
        {
            Ray        ray = new Ray(spawn.position, spawn.forward);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, shotDistance, collisionMask))
            {
                shotDistance = hit.distance;

                if (hit.collider.GetComponent <CarHealth>())
                {
                    hit.collider.GetComponent <CarHealth>().TakeDamage(10, player.GetComponent <CarGenerateInputStrings>().player);
                }
                Debug.Log("Hit something");
            }

            nextPossibleShootTime = Time.time + secondsBetweenShots;

            if (tracer)
            {
                Vector3[] parms = new Vector3[2] {
                    ray.origin, ray.GetPoint(shotDistance)
                };
                StartCoroutine("RenderTracer", parms);
            }

            Debug.DrawRay(ray.origin, shotDistance * ray.direction, Color.red, 1);

            // Instantiate particle system on hit
            GameObject currentParticle = Instantiate(hitParticle, ray.GetPoint(shotDistance), Quaternion.identity);
            currentParticle.transform.LookAt(transform);
            Destroy(currentParticle, 1.0f);

            if (aHandler.CanPlayAudio())
            {
                aHandler.PlayAudio(gunSound);
            }
        }
    }