예제 #1
0
파일: Health.cs 프로젝트: p3rfilov/Survive
    IEnumerator FadeOut(Material material)
    {
        if (material.HasProperty("_Color") && transform.tag != "Player")  // keep player object in the scene
        {
            Color color        = material.color;
            float startOpacity = color.a;
            float t            = 0;

            while (t < timeUntilFade)
            {
                t += Time.deltaTime;
                yield return(null);
            }

            t = 0;
            while (t < fadeTime)
            {
                t += Time.deltaTime;
                float blend = Mathf.Clamp01(t / fadeTime);
                color.a        = Mathf.Lerp(startOpacity, 0, blend);
                material.color = color;
                yield return(null);
            }
            if (color.a <= 0)
            {
                PoolingManager.Remove(gameObject);
            }
        }
    }
예제 #2
0
파일: Health.cs 프로젝트: p3rfilov/Survive
    void Segment()
    {
        if ((timeUntilFade > 0 && fadeTime > 0) || (body != null && coll != null))
        {
            body.detectCollisions = false;
            coll.enabled          = false;
            Destroy(body);
            Destroy(coll);

            Transform[] allParts = GetComponentsInChildren <Transform>();
            foreach (var item in allParts)
            {
                Renderer rend = item.GetComponent <Renderer>();
                if (rend != null)
                {
                    item.gameObject.AddComponent <BoxCollider>();
                    var bodyPart = item.gameObject.AddComponent <Rigidbody>();
                    bodyPart.isKinematic = false;
                    bodyPart.mass        = mass;

                    Material material = rend.material;
                    StartCoroutine(FadeOut(material));
                }
            }
        }
        else
        {
            PoolingManager.Remove(gameObject);
        }
    }
예제 #3
0
 private void OnTriggerEnter(Collider other)
 {
     if (destroyOnCollision)
     {
         var _projectile = other.GetComponent <Projectile>();
         if (ignoreOtherProjectiles && _projectile != null)
         {
             return;
         }
         PoolingManager.Remove(gameObject);
     }
 }
예제 #4
0
    public bool Replenish(Item item)
    {
        Ammo newAmmo       = null;
        Item inventoryItem = null;
        Ammo inventoryAmmo = null;

        newAmmo = item.GetComponent <Ammo>();
        if (newAmmo != null)
        {
            inventoryItem = GetItem(newAmmo.ammoType);
            inventoryAmmo = inventoryItem?.GetComponent <Ammo>();
        }

        if (inventoryAmmo != null && newAmmo != null)
        {
            if (inventoryAmmo.ammoType == newAmmo.ammoType)
            {
                // swap items if picking up IUsable and we are only carrying ammo
                if (!(inventoryItem is IUsable) && item is IUsable)
                {
                    newAmmo.AddAmmo(inventoryAmmo.AllAmmo);
                    RemoveItem(inventoryItem);
                    PoolingManager.Remove(inventoryItem.gameObject, false);
                    EventManager.RaiseOnItemCollected();
                    return(false);
                }
                else if (inventoryAmmo.AddAmmo(newAmmo.AllAmmo))
                {
                    item.gameObject.SetActive(false);
                    PoolingManager.Remove(item.gameObject, false);
                    EventManager.RaiseOnItemCollected();
                    return(true);
                }
            }
        }
        return(false);
    }