- Home /
Red flash for each network player when he gets hit
I am trying to make a multiplayer fps game. I want to flash a red gui texture for each player that gets hit by another player. I instantiate each player as a prefab. I tried to put the gui texture inside the prefab so that each player has its own red gui texture, but this doesnt work cause i cant see the texture after i instantiate it in the network.
For example when player2 gets hit by player1 i want to retrieve the guitexture of player2 and flash it in front of player 2. I hope u understand what i want to do.
Thnx in advance.
I am using this script for flashing the texure:
function Fade (start : float, end : float, length : float, currentObject : GameObject) { //define Fade parmeters if (currentObject.guiTexture.color.a == start){
for (i = 0.0; i < 1.0; i += Time.deltaTime*(1/length)) { //for the length of time currentObject.guiTexture.color.a = Mathf.Lerp(start, end, i); //lerp the value of the transparency from the start value to the end value in equal increments yield; currentObject.guiTexture.color.a = end; // ensure the fade is completely finished (because lerp doesn't always end on an exact value) } //end for
} //end if
} //end Fade
function FlashWhenHit (){ Fade (0, 0.8, 0.5, GUITextureobjectname); yield WaitForSeconds (.01); Fade (0.8, 0, 0.5, GUITextureobjectname); }
Answer by AngryOldMan · Mar 09, 2011 at 04:09 PM
in the players health/life script (what ever gives it hits points and makes it die when they get to zero) add a variable (boolean) called showGui or something like that which turns on after the line that subtracts health. Then have your red flash drawn as a GUI texture (2D texture, not sure if GUI texture is the right phrase) across the whole screen which is only called when showGui variable is true.
i have done that. under the hp=hp-damage i have placed the code for the texture to be drawn and ins$$anonymous$$d of drawing the texture in front of the hurt player it draws in front of the active view.
ah your doing over the network I see. You can either put in a code like if ""(networkView.is$$anonymous$$ine)"" or (and this is messy but if all else fails) make seperate prefabs with seperate scripts (dependin on how many players you can have at one time.
Your answer
![](https://koobas.hobune.stream/wayback/20220613112005im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Screen flashes red when taking damage 3 Answers
Screen Flash When Hit -- Error Help From Pervious Question's Answer 1 Answer
How do I scale a texture so it appears as fixed sized regardless of the display size? 1 Answer
How do I take maximum screenspace for Gui 1 Answer
How to get texture coordinates without using MeshCollider? 0 Answers