- Home /
How to make a Kill Counter
Hey im using a GUI to display how many turrets the player kills but for some reason it wont count up heres the code for the gui:`function Update () { var killCount: int; var globalCounter : GameObject = GameObject.FindWithTag("GlobalVars");
killCount = 0;
if (gameObject.Find("SmallTurret").hit) {
globalCounter.killCount += 1;
print("kill count is now: "+globalCounter.killCount);
}
}`
and the code i put with the turret:
var explosion : Transform;
private static var numKills : int; var killsDisplay : GUIText; if(gameObject.tag == "wormProjectile") { numKills++ ;
killsDisplay.text = "Kills: "+numKills; }
function OnTriggerEnter( hit : Collider )
{ if(hit.gameObject.tag == "wormProjectile")
{ Destroy(hit.gameObject); var exp = Instantiate(explosion, gameObject.transform.position, Quaternion .identity); Destroy(gameObject);
}
As Justin has said below, this is pretty bad form. You should try to write your own code first, and then post when you get stuck. If you have very limited knowledge of Unity or Unityscript/Javascript, then you should probably work through a few tutorials, rather than diving into specific questions like this, or you'll be back here asking how to implement every specific mechanic.
Answer by Justin Warner · Feb 01, 2011 at 02:10 AM
Ooooooooook, please, no one write him a whole script...
Now, for the actual scripting for the kill count, you'll need a health system, or if it's one shot kill, you'll need to have to look at the collider API
http://unity3d.com/support/documentation/ScriptReference/Collider.html
Now, when it hits, you'll need to check out the GUI.
http://unity3d.com/support/documentation/Components/gui-Basics.html
Now, this should cover most of it... Their is also a Destroy() function to make the turret disapear and you can see the instantiate to make a "dead" turrent model appear in its place.
http://unity3d.com/support/documentation/ScriptReference/Object.Instantiate.html
Now, www.Google.com will help with scripting, and now, my fine feathered friend, you're armed to code your own project.
Good luck, and be safe, and PLEASE comment your code if you want people to help you.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Kill Counter --> Score 2 Answers
problem with shooting killing script 1 Answer
Array problem -3 Answers
Combat Script 2 Answers