示例#1
0
    void Shoot()
    {
        RaycastHit hit;

        if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
        {
            Debug.Log(hit.transform);
            ZombieCharacterControl zombie = hit.transform.GetComponent <ZombieCharacterControl>();
            CarController          car    = hit.transform.GetComponent <CarController>();
            TruckController        truck  = hit.transform.GetComponent <TruckController>();


            if (zombie != null)
            {
                zombie.TakeDamage(damage);
            }

            if (car != null)
            {
                car.TakeDamage(damage);
            }

            if (truck != null)
            {
                truck.TakeDamage(damage);
            }
        }
        Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
    }