Пример #1
0
    private void Shoot()
    {
        m_device.TriggerHapticPulse(1500);
        m_remainingCooldown = cooldown;
        RaycastHit hit;

        Vector3 newForward = (transform.forward + transform.up * -1 * angleMultiplier) / 2;

        if (Physics.Raycast(transform.position, newForward, out hit, maxDistance: range))
        {
            Instantiate(impactParticleSystem, hit.point, Quaternion.identity);
            if (hit.transform.gameObject.layer == 9)
            {
                NPCInfo npcInfo = hit.transform.root.gameObject.GetComponent <NPCInfo>();
                npcInfo.health -= damage;
                if (npcInfo.health <= 0.0f)
                {
                    if (npcInfo.triggerScriptOnDeath && npcInfo.triggerScript != null)
                    {
                        npcInfo.triggerScript.Activate();
                    }

                    // If the NPC has a Ragdoll - Activate Ragdoll. Else Destroy GameObject
                    if (npcInfo.puppetMaster)
                    {
                        npcInfo.TriggerPuppetMaster(hit.collider, impactForce, hit.point, 0);
                    }
                    else
                    {
                        Destroy(hit.transform.gameObject);
                    }
                }
            }
        }
    }
Пример #2
0
    void OnHit(RaycastHit hit)
    {
        if (hit.collider.gameObject.layer == 9)
        {
            // Collides with NPC
            NPCInfo npcInfo = hit.collider.transform.root.gameObject.GetComponent <NPCInfo>();
            npcInfo.health -= damage;
            if (npcInfo.health <= 0.0f)
            {
                if (npcInfo.triggerScriptOnDeath && npcInfo.triggerScript != null)
                {
                    npcInfo.triggerScript.Activate();
                }

                // If the NPC has a Ragdoll - Activate Ragdoll. Else Destroy GameObject
                if (npcInfo.puppetMaster)
                {
                    npcInfo.TriggerPuppetMaster(hit.collider, force, transform.position, 0);
                }
                else
                {
                    Destroy(hit.collider.gameObject);
                }
            }
        }
        else if (hit.collider.gameObject.layer == 11)
        {
            // Collides with Player
            PlayerInfo playerInfo = hit.collider.gameObject.transform.root.GetComponent <PlayerInfo>();
            playerInfo.health -= damage;
            if (playerInfo.health <= 0.0f)
            {
                UnityEngine.SceneManagement.SceneManager.LoadScene(GameInfo.mainMenuIndex, UnityEngine.SceneManagement.LoadSceneMode.Single);
            }
        }
        else if (hit.collider.gameObject.layer == 14)
        {
            Shield shield = hit.collider.transform.parent.GetComponent <Shield>();
            if (shield.loseEnergyOnHit)
            {
                shield.GetHit(damage);
            }
        }
        Destroy(gameObject);
    }