- Home /
Hitmark display on hit
i have a raycast hitting an enemy, when i hit the enemy i want a cross to appear like in call of duty or crysis, my probelm is that i have it displaying but it never goes away. how can i get it so that only when i hit the eney to show then if im not dissapear basically what im wanting is a hitmark exaclty like cod or crysis. thanks.
if (hit.collider.gameObject.tag == "Enemy") { displayHits = true; } else { displayHits = false; }
public void OnGUI() { if (displayHits) { GUI.DrawTexture(new Rect(Screen.width / 2 - hitMark.width / 2, Screen.height/2- hitMark.height/2,hitMark.width, hitMark.height), hitMark); }
currently i have just made one that work although it is a very complicated way, im using times, i thought there could be a simpler way to just show the mark every time it hits the enemy and dissapear if you are not
Answer by FLASHDENMARK · May 09, 2011 at 01:53 PM
Hello!
Please tell me if I understood this wrong, but you cant get the hitmarker to disaper again?
I am NO C# dude so there may be some syntax issues. I am sorry about that.
public hitmarkerTime = 0.2; // Again I am no C# guy so I have almost no idea how to declair variables in C#
if (hit.collider.gameObject.tag == "Enemy") { displayHits = true; } else { displayHits = false; }
public void OnGUI() { if (displayHits) { timer(); GUI.DrawTexture(new Rect(Screen.width / 2 - hitMark.width / 2, Screen.height/2- hitMark.height/2,hitMark.width, hitMark.height), hitMark); } }
void timer() { yield WaitForSeconds(hitmarkerTime); displayHits = false; }
YYYYYYYYEEEEEEEEEEEESSSSSSSSSSSSSSSSS!!!!!! Legend mate. i did have to fiddle about with the code but now it works flawlessly, i didnt want to reply until i got it though. anyway thans very much. yeh i know how to convert jscript to c# pretty well so no worries. for c# and yeild you have to right, yeild return new WaitForSeconds(hitmarkerTime); thanks again :)