void Update()
 {
     if (transform.position.y < -100f)
     {
         GuyManager.DestroyGuy(GetComponent <Guy>());
     }
 }
Example #2
0
    void Update()
    {
        _percentAlongSpline += _appliedMoveSpeed * Time.deltaTime;
        transform.position   = _bezierSpline.GetPoint(_percentAlongSpline);

        if (_percentAlongSpline >= 1f)
        {
            FinishedLineCallback();
            GuyManager.DestroyGuy(this);
        }
    }
Example #3
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);
            }
        }
    }
Example #4
0
    public void Initialize()
    {
        GuyManager.RegisterGuy(this);

        BezierSpline[] splines = FindObjectsOfType <BezierSpline>();
        _bezierSpline = splines[Random.Range(0, splines.Length)];

        collider2D.enabled      = true;
        rigidbody2D.isKinematic = true;
        transform.position      = _bezierSpline.GetPoint(0f);

        _appliedMoveSpeed   = _catchupSpeed;
        _percentAlongSpline = 0f;
        enabled             = true;
    }
Example #5
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();
            }
        }
    }
Example #6
0
    IEnumerator WaveRoutine(int waveNum)
    {
        StartWaveCallback();

        int numSpawned = 0;

        while (numSpawned < _enemyCountCurve.Evaluate(waveNum))
        {
            yield return(new WaitForSeconds(_enemySpawnTimeCurve.Evaluate(waveNum)));

            Guy spawnedGuy = GuyManager.SpawnGuy();
            spawnedGuy.Initialize();
            spawnedGuy.FinishedLineCallback -= WaveLostCallback;
            spawnedGuy.FinishedLineCallback += WaveLostCallback;
            spawnedGuy.SetNormalSpeed(_enemySpeedCurve.Evaluate(waveNum));
            numSpawned++;
        }

        GuyManager.GuysClearedCallback += StartNextWave;
        _waveRoutine = null;
    }