Ejemplo n.º 1
0
    }           //fuctions that is begin run every second

    void shoot()
    {
        if (current_ammo > 0)
        {
            muzzle_flash.Play();      //plays the particle system

            current_ammo--;           //takes 1 ammo away from current ammo

            RaycastHit hit;           //creats raycast (invisible line) called hit

            if (Physics.Raycast(fps_cam.transform.position, fps_cam.transform.forward, out hit, range))
            {
                Enemy1 enemy = hit.transform.GetComponent <Enemy1>();                                          //locates an enemy script on the transform in the raycast
                if (enemy != null)                                                                             //if the transform has the enemy script
                {
                    enemy.take_dmg(dmg);                                                                       //takes damage of weapon away from health of the enemy (done in enemy script)
                }

                if (hit.rigidbody != null)                                                                     //if the transform has a rigidbody
                {
                    hit.rigidbody.AddForce(-hit.normal * impact_force);                                        //get knocked backwards (-) by impat force
                }

                GameObject impact = Instantiate(impact_effect, hit.point, Quaternion.LookRotation(hit.normal)); //creates the impact particle system where the raycast lands on the object
                Destroy(impact, 0.25f);                                                                         //destroys the particle gameobject after 1/4 of a second
            }                                                                                                   //if there is an object within range and in the centre of the cameras current orientation
        }
    }                                                                                                           //Fuction that takes care of anything to do with bullets