- Home /
Error, class project
Everytime I input this code it says I have to enter a ";" after every word. Can someone fix this?
public var pickupPrefab:GameObject;
public var numberOfPickups:int = 2;
private var spawnPointList:GameObject[];
private var spawnIndexAvailableList:Array = [];
private var numberOfSpawnPoints:int;
function Awake()
{
GameObject which this script is a Component of
spawnPointList = gameObject.FindGameObjectsWithTag("SpawnPoint");
numberOfSpawnPoints = spawnPointList.length;
if (numberOfPickups > numberOfSpawnPoints)
numberOfPickups = numberOfSpawnPoints;
for (var i:int = 0; i < numberOfSpawnPoints; i++)
{
spawnIndexAvailableList[i] = true;
}
for (var j:int = 0; j < numberOfPickups; j++)
{
SpawnPickup();
}
}
function SpawnPickup()
{
the list
var randomSpawnIndex:int = Random.Range(0, numberOfSpawnPoints);
while (!spawnIndexAvailableList[randomSpawnIndex])
{
randomSpawnIndex = Random.Range(0, numberOfSpawnPoints);
}
var spawnedPickupPosition:Vector3 = spawnPointList[randomSpawnIndex].transform.position;
var spawnedPickupRotation:Quaternion = spawnPointList[randomSpawnIndex].transform.rotation;
var spawnedPickup:GameObject = Instantiate(pickupPrefab, spawnedPickupPosition, spawnedPickupRotation);
that this script is a Component of pickupPrefab to call functions within this sript
spawnedPickup.transform.parent = spawnPointList[randomSpawnIndex].transform;
spawnedPickup.name = randomSpawnIndex.ToString();
spawned in this position
spawnIndexAvailableList[randomSpawnIndex] = false;
}
I usually correct the formatting of people's code, but you don't even have a proper indentation. Please clean it up, select all the code and click the code button (the one with 101 010). Or you can be sure no one will ever answer your question .
All I see is a cluster of letters. Please format your code. I think I can see where your error may occur, but with this messy code I'm really not sure.
I'm afraid that before I can fix your code, someone is going to have to fix you.
I tried formatting the code, but there's a bug in the qato editor. The last part of the post is not in the editable text but appears in the post...
edit There wasn't a bug in the editor. It was just the code that still had some newlines within one of the long lines.
@$$anonymous$$thibodeau2009: Have you ever heard about comments? You can't just write a letter to your friend in between your code.
Single line comments look like this:
// This is a comment
Comments that go over multiple lines looks like this:
/* This is a real
long comment across
multiple lines */
Comments are ignored by the compiler. Everything else have to be valid code.
I did this really quick at the end of class because I just couldn't figure out what was wrong with my $$anonymous$$chers code. Thank you @Bunny83 for not complaining and actually helping. But i know how to do commentary, it was all my $$anonymous$$chers terrible example script that caused the problems. Thanks again.
Answer by Bunny83 · May 21, 2012 at 03:47 PM
This is the most ineffective and dangerous way to pick random spawn points.
This is a simplified and more robust version and furthermore doesn't contain errors ;)
import System.Collections.Generic;
public var pickupPrefab : GameObject;
public var numberOfPickups : int = 2;
private var spawnPointList : GameObject[];
private var availableSpawnPoints : List.<GameObject>;
function Awake()
{
spawnPointList = gameObject.FindGameObjectsWithTag("SpawnPoint");
// create a dynamic copy of the spawnpoint array
availableSpawnPoints = new List.<GameObject>(spawnPointList);
if (numberOfPickups > availableSpawnPoints.Count)
numberOfPickups = availableSpawnPoints.Count;
for (var j = 0; j < numberOfPickups; j++)
{
SpawnPickup();
}
}
function SpawnPickup()
{
if (availableSpawnPoints.Count <= 0)
return; // No more spawnpoints left
var randomSpawnIndex : int = Random.Range(0, availableSpawnPoints.Count);
var spawnPoint : Transform = availableSpawnPoints[randomSpawnIndex].transform;
// remove this spawn point from the available list
availableSpawnPoints.RemoveAt(randomSpawnIndex);
var spawnedPickup:GameObject = Instantiate(pickupPrefab, spawnPoint.position, spawnPoint.rotation);
spawnedPickup.transform.parent = spawnPoint;
spawnedPickup.name = randomSpawnIndex.ToString();
}
Your answer
Follow this Question
Related Questions
Problem with type casting from C# to JS 3 Answers
Children ignoring Parent control. [Solved] 1 Answer
tilt function for moving the character left and right 1 Answer
Touch input on IOS C# 0 Answers
Translating an Array of Transforms 1 Answer