Esempio n. 1
0
    IEnumerator OnMouseUp()
    {
        if (_isPulling)
        {
            _isPulling = false;

            _handSpriteRenderer.sprite = _openHandSprite;
            EndPullingCallback();

            int guysFlung = 0;

            // Toss all our guys off
            for (int i = 0; i < _guysToFling.Count; i++)
            {
                Guy     guy      = _guysToFling[i];
                Vector2 flingVec = _guyInitStopPosition[i] - guy.transform.position;

                if (flingVec.magnitude > _minDistanceToEnableFling)
                {
                    guy.rigidbody2D.isKinematic = false;
                    guy.rigidbody2D.AddForce(flingVec * flingVec.magnitude / _vertSoftSelectRange * _guyFlingSpeed);
                    guy.collider2D.enabled = false;
                    GuyManager.DeregisterGuy(guy);

                    GuyManager.deadGuys++;
                    GuyKilled(GuyManager.deadGuys);

                    guysFlung++;
                }
                else
                {
                    guy.SetMoving(true);
                }
            }

            List <AudioSource> sourcesToPlay = _guyDeathSounds.ToList();
            for (int i = 0; i < Mathf.Min(guysFlung, 2, _guyDeathSounds.Length); i++)
            {
                if (Random.value > 1f - _screamChance)
                {
                    int soundIndex = Random.Range(0, sourcesToPlay.Count);
                    SoundManager.PlaySound(sourcesToPlay[soundIndex]);
                    sourcesToPlay.RemoveAt(soundIndex);
                }
            }

            if (_initPullingWorldPos != _currentPullingWorldPos)
            {
                _bounceBackRoutine = StartCoroutine(BounceBackRoutine());
                yield return(_bounceBackRoutine);
            }
        }
    }
Esempio n. 2
0
    void OnTriggerExit2D(Collider2D other)
    {
        Guy guy = other.GetComponent <Guy>();

        if (guy)
        {
            _hitGuys.Remove(guy);

            if (guy.transform.position.y > transform.position.y + collider2D.offset.y)
            {
                GuyManager.DeregisterGuy(guy);
                guy.Recycle();
            }
        }
    }