Hey guys, I’ve recently been told I need to learn JavaScript as I’m in my second year of university studying Games Design and am having a little trouble. Here’s my problem:
When I hit an enemy (chicken) with my bullet all is well and good and the enemy disappears and does what it is supposed to. I then tried to add a scoring system that gives you +1 to an assigned variable as you hit the 3 targets so the final score would be 3 (add 1 each time). This was fine but when I added the score the gameobject deleted with my destroy function and with that went the assigned variable.
Moving on, to counter that problem I called upon the other script from my gui script which I thought would fix the problem. However, the score doesn’t seem to be adding up (it is not deleting this time) and I cannot see the problem, and yes I have dragged the object from the hierarchy into the script variable slot. Here is my code:
This is my GUI code:
var style : GUIStyle;
var collisionchicken : CollisionChicken;
var chickenHit : int = 0;
function OnTriggerEnter(c:Collider){
if(c.gameObject.tag =="bulletShot")
{
chickenHit++;
}
}
function OnGUI()
{
GUI.Label( Rect(515, 10, 100, 20), ""+ chickenHit.ToString("f0"), style );
}
And here is my script that destroys the chickens:
var explosion : Transform;
var Bwuk : AudioClip;
function OnTriggerEnter(c:Collider){
if(c.gameObject.tag =="bulletShot")
{
audio.PlayOneShot(Bwuk);
yield WaitForSeconds(0.3);
Destroy(gameObject);
var exp = Instantiate(explosion, gameObject.transform.position, Quaternion.identity);
}
}
In case I have missed anything, I will recap quickly. I want the chickenHit variable to add 1 each time the object is destroyed in the external script but at the moment it stays at 0 I know you guys are extremely knowledgeable and look forward to learning from you
Thanks, Jimmy