- Home /
if shield got hit show
hey guys i know i heve alreddy asked somthing like this but maybe you will know what i want with this its a simple idea i have a force shield arround me
now you see it all the time i want it to only show everytime it gots hit
i have the mashine gun and the standard rockerd louncher from the sirst person tut so both rigidbody weapons and raycast weapons
could you please make a script for me i dont know the codes
Answer by Cery · May 14, 2011 at 11:08 AM
Here is my way how i would make it: The shield must have a collider with trigger activated
var Shot : boolean = false; var Timer : float;
function Update (){ //Normaly it's not showen renderer.enabled = false;
if (Shot){ //The time wich defines how long the sphere is showen Timer += Time.deltaTime; //If You make 0.1 its shorter showen if you make 2 it's longer showen if (Timer < 1){ renderer.enabled = true; } //If the time runs out it's dosen't showen else { renderer.enabled = false; Shot = false; } } // Reset the Timer else { Timer = 0; } } // This change Shot if something touches the Forcefield function OnTriggerEnter (){ Shot = true; }
Good luck I hope it works Cery
Ps: There is a better way than mine but i don't know how. Sorry for bad english
yeah it works but when i set the tomer to 0,1 it stil stays to long in face its like one second how do i fix this
Around one second? Thats unusualy but you can sett it to 0.01 or 0.001 it's your choise. You can make it also only one frame you must only say if (Shot){ renderer.enabled = true; Shot = false;} else { renderer.enabled = false; But i thing one frame is to short you wouldn't see it. Cery
Ps: $$anonymous$$aybe your Framerate is too bad $$anonymous$$uch poly's in your scene? Sorry for bad English