- Home /
function execution order
I have a function that I want to call right at the start of my Game Loading.
function increaseCounter()
{
Number++
}
I'm sure you can see that it adds one point to the counter each time. This function is also used on another game object. However it keeps says "unkown identifier 'increaseCounter' " I read some stuff about the compiling order and placed the script with thr original function into the Standard Assets folder but that didnt work. I've also read about Get.Component, is that appropriate for what i want here?
Any pointers on what i need to be doing would be greatly appreciated :)
Thanks!
Hi
The problem might be to do with the script its part of - could you post a little bit more code - the script its defined in, and the script that causing the compile error?
-Chris
Sorry, I'll explain it better. I have a 'Timer.js' script which has the following code:
var HoopNumber : float;
var timer : float;
var startTimer = false;
var destroyTime = 3.0f;
function IncreaseHoops()
{
HoopNumber++;
}
function OnTriggerEnter ()
{
if (gameObject.tag == "startHoop")
{
IncreaseHoops();
startTimer = true;
yield WaitForSeconds(destroyTime);
renderer.enabled = false;
}
}
function Update
{
if(startTimer)
{
timer += Time.detlaTime;
}
}
This script is attached to the 'start hoop' with a tag of "startHoop" in the game (the player races around a track, passing through all the hoops to avoid time penalties) This adds 1 to the hoop timer and starts the timer. It also makes the ring not visible to the player so they can see they have passed through it.
I now want another script that is attached to the rest of the 'normal rings' that adds 1 and makes the ring disappear. This is were I really get stuck. The next script is 'ringPickup.js'. At the $$anonymous$$ute i'm not sure whether I need the script attached to all the hoops? Or do i put it on an empty game object and it will it work with any hoops tagged "Pickup"?
The main issue is the following scripts keeps throwing an error saying unkown identifier 'IncreaseHoops'
var destroyTime = 3.0f;
function OnTriggerEnter()
{
if (gameObject.tag == "Pickup")
{
IncreaseHoops();
yield WaitForSeconds(destroyTime);
renderer.enabled.false;
}
}
$$anonymous$$y hope was this code would get the IncreaseHoops function from the previous script.
Please excuse any typos (unfortunately I cant copy and paste my code) PS This is my first project so if it a simple mistake, then my apologies!
PPS having some trouble with formatting the code here so sorry if it comes out bad!
Thanks
Answer by Nicolaj Schweitz · Feb 17, 2014 at 12:36 PM
Does this compile? - notice the semicolon:
function increaseCounter()
{
Number++;
}
Damn-sorry that was just a type. It does have a semicolon on the actual script.