Guys i have this script for health control but it doesn't seem to work can some one help? Code (csharp): function OnControllerColliderHit(hit : ControllerColliderHit) { if(hit.gameObject.tag == "healthpickup") { Destroy(hit.gameObject); // Destroys Health Box print("Gained 10 Health"); HealthControl.LIVES +=6 ; } }
Not very good with scripting but I guess I could try and help you fix it. Below is the way that I personally would do it and below the code I will explain it a little. Code (csharp): var Script : HealthControl; //This allows you to place the HealthControl script in the Inspector. function OnTriggerEnter(){ //Personally i think it's easier if we use OnTriggerEnter. Destroy(gameObject); // Destroys Health Box print("Gained 10 Health"); Script.LIVES +=10; // Script is the HealthControl script that we added in the Inspector. } So this is the Script that will be placed onto the HealthPickup GameObject. All you have to do is make sure that you have "Is Trigger" selected on this object. This next piece of code will be the GUI Script that will tell us how many lives we currently have. This can be customized with your own skin or icon. You will add this Script to the main camera. Then you will drag the main camera into the "Script" slot of the previous code in the Inspector. This Script must be named "HealthControl". Code (csharp): var LIVES: int = 10; //This is the number of lives which can be changed from the Inspector. function OnGUI () { GUI.Label (Rect (600, 10, 100, 20), "Lives: "+LIVES); //This is just a label telling us how many lives we have. } This should work fine and I hope it helps you. Good luck with the rest of your project and if you have any problems with this script just let me know and I'll try my best to help you if I can.
Some more information would be nice. What is it doing? Your character needs a CharacterController The pickup needs to be tagged "healthpickup"
More details, what doesn't work ? does the function even fire off ? do you even get the print output? More details are needed