Character turning solid black instead of reverting to original

Benjamin Zarb

Character turns transparent until the timer ends, then instead of flicking back to the original colour it turns flat black.

    private Color c;

    void Start(){
    c = thePlayer.rend.color;
    }

public void HurtPlayer(int damageToTake)
    {
        healthCount -= damageToTake;
        UpdateHeartMeter ();
        StartCoroutine ("iFrames");
    }

    IEnumerator iFrames(){
            Physics2D.IgnoreLayerCollision (10, 11, true);
            c.a = 0.5f;
            thePlayer.rend.color = c;
            yield return new WaitForSeconds (2f);
            c.a = 1f;
            thePlayer.rend.color = c;
            Physics2D.IgnoreLayerCollision (10, 11, false);
    }

Example: https://imgur.com/a/jFKXvhW

Ali Kanat

This piece of code works for me i am not sure how you access the SpriteRenderer problem might be there. I only started the coroutine with click of a button since i do not know when you apply this. This code is attached to a Sprite.

private Color c;
// Use this for initialization
void Start () {
    c = gameObject.GetComponent<SpriteRenderer>().color;
}

// Update is called once per frame
void Update () {
    if(Input.GetKeyDown(KeyCode.Mouse0))
    {
        StartCoroutine("ChangeColor");
    }
}
IEnumerator ChangeColor()
{
    c.a = 0.5f;
    gameObject.GetComponent<SpriteRenderer>().color = c;
    yield return new WaitForSeconds(2);
    c.a = 1f;
    gameObject.GetComponent<SpriteRenderer>().color = c;
}

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Libgdx images from pixmaps are drawn solid black

分類Dev

Desktop shows a white or black background instead of wallpapers

分類Dev

Android: Toolbar text is coming as black instead of white

分類Dev

Turning a string into an array and saving it as a new array, doesn't return original array

分類Dev

Last brace → } are turning red instead of green, but the script works normally (Google App Script)

分類Dev

HttpSessionState returns HTML entity instead of character

分類Dev

Script to batch rename based on first character of original filename?

分類Dev

Angular 2 Observables - Return original observable, instead of switchMap/combineLatest

分類Dev

未定義のメソッドDompdf \ Renderer \ TableCell :: _ border_1px solid black()の呼び出し

分類Dev

Sequence Alignment Algorithm with a group of characters instead of one character

分類Dev

how to prevent dataframe columns being classed as character instead of numeric

分類Dev

Clipping a volume in Three.Js giving Black area instead of Inner Material

分類Dev

Android gps programmatically turning on and turning off

分類Dev

Reverting to a specific commit based on commit id with Git?

分類Dev

git-stash changes without reverting

分類Dev

Git Immersion Labs 16, Creating a Reverting Commit

分類Dev

Canceled event is not reverting RadTextBox to initial value

分類Dev

SOLID、SRP、IComparable

分類Dev

sklearn: Turning off warnings

分類Dev

UIVisualEffectView turning gray (not working)

分類Dev

OpenMP nesting not turning off

分類Dev

Turning off auto login

分類Dev

Turning an if statement to a false check

分類Dev

Actionscript 3 objects not turning

分類Dev

Turning a list into a string or a word

分類Dev

Turning an existing array into a multidimensional

分類Dev

Pythonでsearch_characterをoriginal_stringの置換に置き換える方法

分類Dev

Reverting to an old version of my meteor project with git, as well as reverting to old packages

分類Dev

getting special character instead of single quote when writing to HTML file using nodeJS and cheerio

Related 関連記事

  1. 1

    Libgdx images from pixmaps are drawn solid black

  2. 2

    Desktop shows a white or black background instead of wallpapers

  3. 3

    Android: Toolbar text is coming as black instead of white

  4. 4

    Turning a string into an array and saving it as a new array, doesn't return original array

  5. 5

    Last brace → } are turning red instead of green, but the script works normally (Google App Script)

  6. 6

    HttpSessionState returns HTML entity instead of character

  7. 7

    Script to batch rename based on first character of original filename?

  8. 8

    Angular 2 Observables - Return original observable, instead of switchMap/combineLatest

  9. 9

    未定義のメソッドDompdf \ Renderer \ TableCell :: _ border_1px solid black()の呼び出し

  10. 10

    Sequence Alignment Algorithm with a group of characters instead of one character

  11. 11

    how to prevent dataframe columns being classed as character instead of numeric

  12. 12

    Clipping a volume in Three.Js giving Black area instead of Inner Material

  13. 13

    Android gps programmatically turning on and turning off

  14. 14

    Reverting to a specific commit based on commit id with Git?

  15. 15

    git-stash changes without reverting

  16. 16

    Git Immersion Labs 16, Creating a Reverting Commit

  17. 17

    Canceled event is not reverting RadTextBox to initial value

  18. 18

    SOLID、SRP、IComparable

  19. 19

    sklearn: Turning off warnings

  20. 20

    UIVisualEffectView turning gray (not working)

  21. 21

    OpenMP nesting not turning off

  22. 22

    Turning off auto login

  23. 23

    Turning an if statement to a false check

  24. 24

    Actionscript 3 objects not turning

  25. 25

    Turning a list into a string or a word

  26. 26

    Turning an existing array into a multidimensional

  27. 27

    Pythonでsearch_characterをoriginal_stringの置換に置き換える方法

  28. 28

    Reverting to an old version of my meteor project with git, as well as reverting to old packages

  29. 29

    getting special character instead of single quote when writing to HTML file using nodeJS and cheerio

ホットタグ

アーカイブ