- Home /
Need help on a semicolon error
Need to put a semicolon at the end of line 91 but it won't work. How do i do it?
pragma strict
static var spawner : Spawner;
var caches : ObjectCache[];
var activeCachedObjects : Hashtable;
class ObjectCache { var prefab : GameObject; var cacheSize : int = 10;
private var objects : GameObject[];
private var cacheIndex : int = 0;
function Initialize () {
objects = new GameObject[cacheSize];
// Instantiate the objects in the array and set them to be inactive
for (var i = 0; i < cacheSize; i++) {
objects[i] = MonoBehaviour.Instantiate (prefab) as GameObject;
objects[i].SetActiveRecursively (false);
objects[i].name = objects[i].name + i;
}
}
function GetNextObjectInCache () : GameObject {
var obj : GameObject = null;
// The cacheIndex starts out at the position of the object created
// the longest time ago, so that one is usually free,
// but in case not, loop through the cache until we find a free one.
for (var i : int = 0; i < cacheSize; i++) {
obj = objects[cacheIndex];
// If we found an inactive object in the cache, use that.
if (!obj.active)
break;
// If not, increment index and make it loop around
// if it exceeds the size of the cache
cacheIndex = (cacheIndex + 1) % cacheSize;
}
// The object should be inactive. If it's not, log a warning and use
// the object created the longest ago even though it's still active.
if (obj.active) {
Debug.LogWarning (
"Spawn of " + prefab.name +
" exceeds cache size of " + cacheSize +
"! Reusing already active object.", obj);
Spawner.Destroy (obj);
}
// Increment index and make it loop around
// if it exceeds the size of the cache
cacheIndex = (cacheIndex + 1) % cacheSize;
return obj;
}
}
function Awake () { // Set the global variable spawner ;
// Total number of cached objects
var amount : int = 0;
// Loop through the caches
for (var i = 0; i < caches.length; i++) {
// Initialize each cache
caches[i].Initialize ();
// Count
amount += caches[i].cacheSize;
}
// Create a hashtable with the capacity set to the amount of cached objects specified
activeCachedObjects = new Hashtable (amount);
}
static function Spawn (prefab : GameObject, position : Vector3, rotation : Quaternion) : GameObject { var cache : ObjectCache = null;
// Find the cache for the specified prefab
if (spawner) {
for (var i = 0; i ;) i++; {
(spawner[i].prefab == prefab) :
cache } spawner;
}
EOF;
EOF;
// If there's no cache for this prefab type, just instantiate normally
if (cache == null) {
return Instantiate (prefab, position, rotation as GameObject);
}
// Find the next object in the cache
var obj : GameObject = cache.GetNextObjectInCache ();
// Set the position and rotation of the object
obj.transform.position = position;
obj.transform.rotation = rotation;
// Set the object to be active
obj.SetActiveRecursively (true);
spawner.activeCachedObjects[obj] = true;
return obj;
EOF;
} EOF, ) { (spawner && spawner.activeCachedObjects.ContainsKey (objectToDestroy)) { objectToDestroy.SetActiveRecursively (false); spawner.activeCachedObjects[objectToDestroy] = false; } else { objectToDestroy.Destroy (objectToDestroy); } }
WOW, syntax highliht and alternate row colors!!! :D awesome!! Now it would be quite useful if there were a "copy raw" option so if people try to copy the code they don't have to delete the line numbers! EDIT: excuse me, it's working as it is :)
Answer by CapeNelson · Jan 26, 2013 at 11:39 PM
for (var i = 0; i ;) i++; { (spawner[i].prefab == prefab) : cache } spawner; } EOF; EOF; I'm sorry, correct me if i'm wrong, but it seems like you have just copied bits of this code from somewhere and tried to use it without understanding it. There are a lot of syntax errors such as the for loop above. It seems that you had a message saying 'expected EOF at line...' so you just wrote 'EOF' in the code twice. EOF means 'End of file' and usually occurs if you missed a closing curly bracket,if (spawner) {
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
No appropriate version of 'UnityEngine.Object.Instantiate. Please Help :( 1 Answer
Exception error 1 Answer
Problem with camera in game mode. 0 Answers