Beispiel #1
0
    private void Update()
    {
        // Don't set a state since an animation is playing
        if (_playingAnimation)
        {
            _lastIndex = -1;
            return;
        }

        int directionIndex = BillboardDirection.GetDirection8(transform, _player.transform, _frontCutoff);

        if (_activated)
        {
            if (directionIndex != _lastIndex)
            {
                PlayActiveState(directionIndex);
                _lastIndex = directionIndex;
            }
        }
        else
        {
            if (directionIndex != _lastIndex)
            {
                PlayInactiveState(directionIndex);
                _lastIndex = directionIndex;
            }
        }
    }
Beispiel #2
0
    /// <summary>
    /// Play an animation of emission maps
    /// </summary>
    /// <param name="animation">A list of texture arrays
    /// Each list item represents a frame of the animation
    /// Each array item represents that frame in a different direction out of eight</param>
    /// <param name="playSpeed">The length of one frame</param>
    /// <param name="index">The current frame index</param>
    /// <param name="animationLength">The total amount of frames in this animation</param>
    /// <returns></returns>
    private IEnumerator PlayAnimE(List<Texture[]> animation, float playSpeed, int index, int animationLength)
    {
        int direction = BillboardDirection.GetDirection8(transform, _player.transform, _frontCutoff);
        _spriteRenderer.material.SetTexture("_EmissionMap", animation[index][direction]);

        yield return new WaitForSeconds(playSpeed);

        if (index < animationLength - 1)
        {
            StartCoroutine(PlayAnimE(animation, playSpeed, index + 1, animationLength));
        }
    }
Beispiel #3
0
    /// <summary>
    /// Play an animation
    /// </summary>
    /// <param name="animation">A list of sprite arrays
    /// Each list item represents a frame of the animation
    /// Each array item represents that frame in a different direction out of eight</param>
    /// <param name="playSpeed">The length of one frame</param>
    /// <param name="index">The current frame index</param>
    /// <param name="animationLength">The total amount of frames in this animation</param>
    /// <returns></returns>
    private IEnumerator PlayAnim(List<Sprite[]> animation, float playSpeed, int index, int animationLength)
    {
        int direction = BillboardDirection.GetDirection8(transform, _player.transform, _frontCutoff);
        _spriteRenderer.sprite = animation[index][direction];

        yield return new WaitForSeconds(playSpeed);

        if (index < animationLength - 1)
        {
            StartCoroutine(PlayAnim(animation, playSpeed, index + 1, animationLength));
        }
        else
        {
            _playingAnimation = false;
        }
    }
    /// <summary>
    /// Cycles between two animation frames
    /// </summary>
    /// <param name="playSpeed">The length of one frame</param>
    /// <param name="index">The current frame of animation</param>
    /// <returns></returns>
    private IEnumerator PlayAnimation(float playSpeed, int index)
    {
        int direction = BillboardDirection.GetDirection5(transform, _player.transform, _frontCutoff);

        _spriteRenderer.sprite = _flyAnim[index][direction];
        _spriteRenderer.material.SetTexture("_EmissionMap", _flyAnimE[index][direction]);

        yield return(new WaitForSeconds(playSpeed));

        if (index < 1)
        {
            StartCoroutine(PlayAnimation(playSpeed, index + 1));
        }
        else
        {
            StartCoroutine(PlayAnimation(playSpeed, 0));
        }
    }
    private void Update()
    {
        int directionIndex = BillboardDirection.GetDirection8(transform, _player.transform, _frontCutoff);

        PlayAnimation(directionIndex);
    }