示例#1
0
        private void OnTriggerEnter(Collider other)
        {
            if (other.CompareTag("Tree"))
            {
                _energy   = Mathf.Min(_energy + other.GetComponent <FishFood>().Eat(_bite), _capacity);
                _lastTree = other.gameObject.GetComponent <FishFood>();
            }
            else if (other.CompareTag("Predator"))
            {
                Predator predator = other.GetComponent <Predator>();
                if (predator.Energy >= predator.Capacity)
                {
                    return;
                }
                predator.Eat();
                Die();
            }
            else if (!_isMale && other.CompareTag("Fish"))
            {
                Fish fish = other.gameObject.GetComponent <Fish>();
                if (fish._isMale == _isMale || Time.time < _nextReproduction || Time.time < fish._nextReproduction ||
                    fish._energy <= fish._capacity / 2.0f || _energy <= _capacity / 2.0f)
                {
                    return;
                }

                if (Random.value > NoDiscriminationChance)
                {
                    float alpha1     = transform.GetChild(0).gameObject.GetComponent <InhibitorActivator>().GetAlpha();
                    float alpha2     = other.transform.GetChild(0).gameObject.GetComponent <InhibitorActivator>().GetAlpha();
                    float skinFactor = Mathf.Abs(alpha1 - alpha2);
                    float dist       = Vector3.Distance(transform.localScale, other.transform.localScale);
                    if (skinFactor > MaxSDifference || dist > MaxTDifference)
                    {
                        return;
                    }
                }

                fish.UpdateNexReproduction();
                UpdateNexReproduction();
                Reproduce(fish);
                if (Random.value <= DoubleChildProb)
                {
                    Reproduce(fish);
                }
            }
        }