Exemple #1
0
    void FireHitscan()
    {
        Vector3    inaccuracy = new Vector3((Random.value - 0.5f) * accuracyFactor, (Random.value - 0.5f) * accuracyFactor, (Random.value - 0.5f) * accuracyFactor);
        RaycastHit hit;

        if (Physics.Raycast(playerCamera.transform.position, playerCamera.transform.forward + inaccuracy, out hit, range))
        {
            EntityScript_NPC nttscp = hit.transform.GetComponent <EntityScript_NPC>();
            if (nttscp != null)
            {
                nttscp.TakeDamage(damage);
            }
            if (hit.rigidbody != null)
            {
                hit.rigidbody.AddForce(-hit.normal * impactForce);
            }
            //particle management
            if (hit.transform.tag == "NPC")
            {
                GameObject impactGO = Instantiate(impactBlood, hit.point, Quaternion.LookRotation(hit.normal));
                Destroy(impactGO, 2f);
            }
            else
            {
                GameObject impactGO = Instantiate(impactGeneric, hit.point, Quaternion.LookRotation(hit.normal));
                GameObject decalGO  = Instantiate(hole_Generic, hit.point, Quaternion.LookRotation(hit.normal));
                Destroy(impactGO, 2f);
            }
        }
    }
Exemple #2
0
    void Melee()
    {
        RaycastHit meleeHit;

        if (Physics.Raycast(playerCamera.transform.position, playerCamera.transform.forward, out meleeHit, meleeRange))
        {
            EntityScript_NPC nttscp = meleeHit.transform.GetComponent <EntityScript_NPC>();
            if (nttscp != null)
            {
                nttscp.TakeDamage(meleeDamage);
            }
            if (meleeHit.rigidbody != null)
            {
                meleeHit.rigidbody.AddForce(-meleeHit.normal * impactForce);
            }
            //particle management
            if (meleeHit.transform.tag == "NPC")
            {
                GameObject impactGO = Instantiate(impactBlood, meleeHit.point, Quaternion.LookRotation(meleeHit.normal));
                Destroy(impactGO, 2f);
            }
        }
    }