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
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]
コメントを追加