Exemple #1
0
    // Start is called before the first frame update
    private void Start()
    {
        _hasSpawned       = false;
        _sprRendRef.color = new Color(0, 1, 1);
        _curCol           = _sprRendRef.color;
        _colToChange      = ColorMain.RED;

        StartFlashing();
    }
Exemple #2
0
    /// <summary>
    /// Makes the Rainbow effect change colors
    /// </summary>
    /// <returns>IEnumerator</returns>
    private IEnumerator StarPowerUpdate()
    {
        // Continue flashing the rainbow until this is destroyed
        while (true)
        {
            // If we are to increase red
            if (_colToChange == ColorMain.RED)
            {
                // Increase red, decrement green
                _curCol.r += Time.deltaTime * _speed;
                _curCol.g -= Time.deltaTime * _speed;
                // If we reached max red, swap _colToChange
                if (_curCol.r >= 1)
                {
                    _colToChange += 1;
                }
                yield return(null);
            }
            // If we are to increase green
            else if (_colToChange == ColorMain.GREEN)
            {
                // Increase green, decrement blue
                _curCol.g += Time.deltaTime * _speed;
                _curCol.b -= Time.deltaTime * _speed;
                // If we reached max green, swap _colToChange
                if (_curCol.g >= 1)
                {
                    _colToChange += 1;
                }
                yield return(null);
            }
            // If we are to increase blue
            else
            {
                // Increase blue, decrement red
                _curCol.b += Time.deltaTime * _speed;
                _curCol.r -= Time.deltaTime * _speed;
                // If we reached max blue, swap _colToChange
                if (_curCol.b >= 1)
                {
                    _colToChange = ColorMain.RED;
                }
                yield return(null);
            }
            // Set the color of this sprite renderer
            _sprRendRef.color = _curCol;
            // Change the particle system's color
            ParticleSystem.MainModule tempMain = _myPartSys.main;
            tempMain.startColor = _curCol;

            yield return(null);
        }
    }
Exemple #3
0
    /// <summary>
    /// Begin the rainbow effect
    /// </summary>
    public void StartFlashing()
    {
        // Set the default values
        _curCol      = _sprRendRef.color;
        _colToChange = ColorMain.RED;
        // If we haven't spawend the particle system yet, spawn it
        if (!_hasSpawned)
        {
            //Debug.Log("Hello from " + this.name);
            // Instantiate it
            GameObject partSysObj = Instantiate(_partSysObj);
            // Have it be centered on this character
            partSysObj.transform.SetParent(this.transform);
            partSysObj.transform.localPosition = Vector3.zero;
            // Get the ParticleSystem off it, so we can change its colors
            _myPartSys = partSysObj.GetComponent <ParticleSystem>();

            _hasSpawned = true;
        }
        StopAllCoroutines();
        // Start the rainbow effect
        StartCoroutine(StarPowerUpdate());
    }