Пример #1
0
    void Shoot()
    {
        muzzleFlash.Play();

        RaycastHit hit;

        if (Physics.Raycast(Cam.transform.position, Cam.transform.forward, out hit, range))
        {
            Debug.Log(hit.transform.name);

            EnemyUnit target = hit.transform.root.GetComponent <EnemyUnit>();
            if (target != null)
            {
                target.DealDamage(1);
            }

            if (hit.collider.sharedMaterial != null)
            {
                string materialName = hit.collider.sharedMaterial.name;

                switch (materialName)
                {
                case "Sand":
                    SpawnDecal(hit, sandHitEffect);
                    break;

                case "Wood":
                    SpawnDecal(hit, woodHitEffect);
                    break;

                case "Meat":
                    SpawnDecal(hit, fleshHitEffects[Random.Range(0, fleshHitEffects.Length)]);
                    break;

                case "Character":
                    SpawnDecal(hit, fleshHitEffects[Random.Range(0, fleshHitEffects.Length)]);
                    break;
                }
            }
        }
    }