コード例 #1
0
 public void UpdateBar()
 {
     Bar.SetValue(
         Health.CurrentValue /
         Health.MaxValue
         );
     BarColorShifter.ShiftToColor(new Color(0, 1, 0, 0), new Color(0, 1, 0, 1));
     BaseBarColorShifter.ShiftToColor(new Color(1, 0, 0, 0), new Color(1, 0, 0, 1));
     StartCoroutine(ShiftBackAfter(DisplayForXSecondsOnUpdate));
 }
コード例 #2
0
ファイル: BillyController.cs プロジェクト: ZayshaaCodes/LD46
    private void Update()
    {
        var overlapped = Physics.OverlapSphere(transform.position, 20, _foodMask.value);

        // Debug.Log(string.Join(" - ", colliders.ToList()));

        var diff = hunger - thirst;

        _isHungry = diff > 0;

        //if he has no targe, set one
        if (TargetItem == null)
        {
            SeekNearestTarget(overlapped, _isHungry);
        }

        searchTimer -= Time.deltaTime;
        if (searchTimer < 0)
        {
            searchTimer += 2;
            SeekNearestTarget(overlapped, _isHungry);
        }

        //nom nom
        for (int i = 0; i < activelyEating.Count; i++)
        {
            var food = activelyEating[i];
            if (food == null)
            {
                continue;
            }
            food.EatFood(foodConsumeRate);

            switch (food.foodType)
            {
            case FoodType.GoodFood:
                hunger -= foodConsumeRate * 3 * Time.deltaTime;
                break;

            case FoodType.GoodDrink:
                thirst -= foodConsumeRate * 3 * Time.deltaTime;
                if (thirst < 0)
                {
                    thirst = 0;
                }
                break;

            case FoodType.BadFood:
                hunger -= foodConsumeRate * 2 * Time.deltaTime;
                sugar  += foodConsumeRate * 2 * Time.deltaTime;
                break;

            case FoodType.BadDrink:
                thirst -= foodConsumeRate * 2 * Time.deltaTime;
                sugar  += foodConsumeRate * 2 * Time.deltaTime;
                if (thirst < 0)
                {
                    thirst = 0;
                }
                break;
            }
        }

        thirst += Time.deltaTime * foodConsumeRate * .3f;
        hunger += Time.deltaTime * foodConsumeRate * .3f;

        if (thirst > 90 || hunger > 90 || sugar > 90)
        {
            health -= Time.deltaTime * 10f;
        }

        sugar -= Time.deltaTime * foodConsumeRate * .125f;

        sugar  = Mathf.Clamp(sugar, 0, 100);
        thirst = Mathf.Clamp(thirst, 0, 100);
        hunger = Mathf.Clamp(hunger, 0, 100);

        healthBar.SetValue(health);
        sugarBar.SetValue(sugar);
        hungerBar.SetValue(hunger);
        thirstBar.SetValue(thirst);

        if (health < 0)
        {
            LevelControler.Instance.GameOver();
        }

        anim.SetFloat(Speed_AnimParam, _agent.velocity.magnitude);
        anim.SetFloat(Health_AnimParam, health);
    }