- Home /
Flash player when taking damage
How would I make my player flash red when he takes damage ? I have created this damage script :
using UnityEngine;
using System.Collections;
public class PlayerDamage : MonoBehaviour {
public float damageCooldown = 1.0f; // cooldown time
private float cooldownTimer = 0.0f;
public int damage = 10;
void Start () {
}
void Update () {
cooldownTimer -= Time.deltaTime;
}
void OnCollisionEnter2D(Collision2D col){
if ( cooldownTimer <= 0 )
{
col.gameObject.BroadcastMessage("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
cooldownTimer = damageCooldown;
}
}
}
Problem is, I tried changing the renderer but it was to no prevail. The flash I would like to achieve is something like the damage effect in minecraft. Link
Answer by shopguy · Mar 14, 2014 at 11:19 PM
Create 2 different textures, then you can get fancy with your coloring/styles. You can see this forum post for help with material.SetTexture if needed. Or the reference found here.
Or if you are using a Difuse shader, or any shader that supports material colors, see this post about changing the material color. Do know that it will change it for all objects using that material, so make a separate material if you currently share it with other objects. I'm currently using Unlit shaders in my project, so not an option.
Answer by nazia08 · Mar 15, 2014 at 04:46 AM
If you use Internet Explorer go to Tools >> Internet Options >> Security Tab >> change the level to medium high >> click apply >> click ok and try to install the component again.
Your answer
Follow this Question
Related Questions
Melee-hits being recognized too often 1 Answer
FallDamage being given continously instead of just once 1 Answer
Armour / Damage System RPG-like? 2 Answers
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer