Hello I am having problems when compiling this project. Upon start it should move the "pieces" into place using this code:
playerOne.transform.position.x = waypoints1[playerOnePoints][0];
playerOne.transform.position.z = waypoints1[playerOnePoints][1];
playerTwo.transform.position.x = waypoints2[playerTwoPoints][0];
playerTwo.transform.position.z = waypoints2[playerTwoPoints][1];
However when i compiled it and ran it, it did not place the transforms at the desired location nor any location. Also the checking for completed questions does work in the editor but not in the compiled version. Here is a link to the project if you wish to compile it and test it in the editor yourself: http://www.mediafire.com/?q475p9gtfab0vpo I appreciate any help or suggestions.
var speed : float = 50.0;
var move : int = 0;
var currentPlayer : int = 1;
var players: int = 2;
var playerOne : Transform;
var playerTwo : Transform;
var playerOnePoints : int = 0;
var playerTwoPoints : int = 0;
var finalScore : int = 0;
var questionAmount : float = 1.0;
var questions : Array;
var currentQuestion : int = 0;
var questionCheck : int = 0;
var n : int = 0;
var q : int = 0;
var timerPerQuestion : int = 3000;
var questionAllUsed : boolean = false;
var winnerBanner : boolean = false;
var lastQuestionDone : boolean = false;
var keepGoing : boolean = true;
var numOfQuestions : int = 0;
var correctA : boolean = false;
var delay : float = 3.0;
var done : float = 0.0;
var waypoints1 : Array;
var waypoints2 : Array;
var customSkin : GUISkin;
//Textures
var questionBoard : Texture2D;
var continueButton : Texture2D;
var goldStar : Texture2D;
var correct : Texture2D;
var incorrect : Texture2D;
var mainMenu : Texture2D;
var startGameButton : Texture2D;
var quitGameButton : Texture2D;
var initialButton : boolean = true;
var waitTimer : int = 0;
var waitTimerActive : boolean = false;
var answerMark : int = 0;
var continueCorrectButton : boolean = false;
var continueIncorrectButton : boolean = false;
var winner : boolean = false;
var playerOneWinner : Texture2D;
var playerTwoWinner : Texture2D;
var TieWinner : Texture2D;
var mainMenuButton : Texture2D;
var showQuestion : boolean = false;
var startGame : boolean = true;
var correctSound : AudioClip;
var incorrectSound: AudioClip;
var spawn1 : Transform;
var waypointOne1 : Transform;
var waypointOne2 : Transform;
var waypointOne3 : Transform;
var waypointOne4 : Transform;
var waypointOne5 : Transform;
var waypointOne6 : Transform;
var waypointOne7 : Transform;
var waypointOne8 : Transform;
var waypointOne9 : Transform;
var waypointOne10 : Transform;
var waypointOne11 : Transform;
var waypointOne12 : Transform;
var waypointOne13 : Transform;
var waypointOne14 : Transform;
var waypointOne15 : Transform;
var seperation : boolean = false;
var spawn2 : Transform;
var waypointTwo1 : Transform;
var waypointTwo2 : Transform;
var waypointTwo3 : Transform;
var waypointTwo4 : Transform;
var waypointTwo5 : Transform;
var waypointTwo6 : Transform;
var waypointTwo7 : Transform;
var waypointTwo8 : Transform;
var waypointTwo9 : Transform;
var waypointTwo10 : Transform;
var waypointTwo11 : Transform;
var waypointTwo12 : Transform;
var waypointTwo13 : Transform;
var waypointTwo14 : Transform;
var waypointTwo15 : Transform;
var correctAnswer : boolean = false;
var incorrectAnswer : boolean = false;
var escHit : boolean = false;
var scripts :boolean = true;
var escTimer : float = 20;
var quizQuestions : int = 0;
function Start () {
currentQuestion = parseInt(Random.Range(0,3));
questions = [
["question1","answer11","answer12","answer13","answer14","1","0"],
["question2","answer21","answer22","answer23","answer24","2","0"],
["question3","answer31","answer32","answer33","answer34","3","0"],
["question4","answer41","answer42","answer43","answer44","3","0"],
["question5","answer51","answer52","answer53","answer54","3","0"]
];
numOfQuestions = questions.length;
Debug.Log(numOfQuestions);
//waypoints for player 1
waypoints1 = [
[spawn1.position.x,spawn1.position.z,"0"],
[waypointOne1.position.x,waypointOne1.position.z,"1"],
[waypointOne2.position.x,waypointOne2.position.z,"2"],
[waypointOne3.position.x,waypointOne3.position.z,"3"],
[waypointOne4.position.x,waypointOne4.position.z,"4"],
[waypointOne5.position.x,waypointOne5.position.z,"5"],
[waypointOne6.position.x,waypointOne6.position.z,"6"],
[waypointOne7.position.x,waypointOne7.position.z,"7"],
[waypointOne8.position.x,waypointOne8.position.z,"8"],
[waypointOne9.position.x,waypointOne9.position.z,"9"],
[waypointOne10.position.x,waypointOne10.position.z,"10"],
[waypointOne11.position.x,waypointOne11.position.z,"11"],
[waypointOne12.position.x,waypointOne12.position.z,"12"],
[waypointOne13.position.x,waypointOne13.position.z,"13"],
[waypointOne14.position.x,waypointOne14.position.z,"14"],
[waypointOne15.position.x,waypointOne15.position.z,"15"]
];
//waypoints for plazer 2
waypoints2 = [
[spawn2.position.x,spawn2.position.z,"0"],
[waypointTwo1.position.x,waypointTwo1.position.z,"1"],
[waypointTwo2.position.x,waypointTwo2.position.z,"2"],
[waypointTwo3.position.x,waypointTwo3.position.z,"3"],
[waypointTwo4.position.x,waypointTwo4.position.z,"4"],
[waypointTwo5.position.x,waypointTwo5.position.z,"5"],
[waypointTwo6.position.x,waypointTwo6.position.z,"6"],
[waypointTwo7.position.x,waypointTwo7.position.z,"7"],
[waypointTwo8.position.x,waypointTwo8.position.z,"8"],
[waypointTwo9.position.x,waypointTwo9.position.z,"9"],
[waypointTwo10.position.x,waypointTwo10.position.z,"10"],
[waypointTwo11.position.x,waypointTwo11.position.z,"11"],
[waypointTwo12.position.x,waypointTwo12.position.z,"12"],
[waypointTwo13.position.x,waypointTwo13.position.z,"13"],
[waypointTwo14.position.x,waypointTwo14.position.z,"14"],
[waypointTwo15.position.x,waypointTwo15.position.z,"15"]
];
playerOne.transform.position.x = waypoints1[playerOnePoints][0];
playerOne.transform.position.z = waypoints1[playerOnePoints][1];
playerTwo.transform.position.x = waypoints2[playerTwoPoints][0];
playerTwo.transform.position.z = waypoints2[playerTwoPoints][1];
}
// buttons and questions
function OnGUI () {
if( startGame == true)
{
GUI.Label (Rect (0,0,700,550),mainMenu);
GUI.Label (Rect (Screen.width - (Screen.width/2)-100,Screen.height - (Screen.height/2)-300,200,100), "Sarah's Quiz");
if(GUI.Button (Rect (Screen.width - (Screen.width/2)-100,Screen.height - (Screen.height/2)-75,200,100), startGameButton))
{
startGame = false;
}
if(GUI.Button (Rect (Screen.width - (Screen.width/2)-100,Screen.height - (Screen.height/2)+150,200,100), quitGameButton))
{
Application.Quit();
}
}
else
{
GUI.skin = customSkin;
// Make a background box
GUI.Label (Rect (25,500,4000,20),"Player Turn: " + currentPlayer);
GUI.Label (Rect (25,50,4000,20),"Player 1 Score " + playerOnePoints);
GUI.Label (Rect (25,100,4000,20),"Player 2 Score " + playerTwoPoints);
if(winner)
{
if(GUI.Button (Rect (Screen.width - (Screen.width/2)+150,Screen.height - (Screen.height/2)+150,100,100), mainMenuButton))
{
startGame = true;
}
}
if(winner && currentPlayer == 1)
{
GUI.Label (Rect (Screen.width - (Screen.width/2),Screen.height - (Screen.height/2),700,550),playerOneWinner);
}
if(winner && currentPlayer == 1)
{
GUI.Label (Rect (Screen.width - (Screen.width/2),Screen.height - (Screen.height/2),700,550),playerTwoWinner);
}
if(winner && currentPlayer == 3)
{
GUI.Label (Rect (Screen.width - (Screen.width/2),Screen.height - (Screen.height/2),700,550),TieWinner);
}
if((initialButton || continueCorrectButton || continueIncorrectButton))
{
if(GUI.Button (Rect (Screen.width - (Screen.width/2)+150,Screen.height - (Screen.height/2)+150,100,100), continueButton))
{
quizQuestions++;
answerMark = 0;
Debug.Log("CLICK!OK");
if(initialButton)
{
showQuestion = true;
initialButton = false;
}
if(continueCorrectButton)
{
Debug.Log("CORRECT");
AudioSource.PlayClipAtPoint(correctSound, Camera.main.transform.position);
move = 1;
questions[currentQuestion][6] = "1";
Debug.Log("A1");
continueCorrectButton = false;
if(currentPlayer == 1)
{
playerOnePoints++;
playerOne.transform.position.x = waypoints1[playerOnePoints][0];
playerOne.transform.position.z = waypoints1[playerOnePoints][1];
}
if(currentPlayer == 2)
{
playerTwoPoints++;
playerTwo.transform.position.x = waypoints2[playerTwoPoints][0];
playerTwo.transform.position.z = waypoints2[playerTwoPoints][1];
}
}
if(continueIncorrectButton)
{
questions[currentQuestion][6] = "1";
move = 2;
AudioSource.PlayClipAtPoint(incorrectSound, Camera.main.transform.position);
continueIncorrectButton = false;
}
if(quizQuestions == numOfQuestions)
{
Debug.Log("IN QUIZ QUESTIONS");
if(playerOnePoints == playerTwoPoints)
{
winner=true;
showQuestion = false;
currentPlayer = 3;
Debug.Log("HIDING!3");
}
else
{
if(playerOnePoints == ((numOfQuestions-1)/2))
{
showQuestion = false;
winner = true;
currentPlayer = 1;
Debug.Log("HIDING!1");
}
if(playerTwoPoints == ((numOfQuestions-1)/2))
{
winner=true;
showQuestion = false;
currentPlayer = 2;
Debug.Log("HIDING!2");
}
}
}
}
}
if( showQuestion == true)
{
GUI.Label (Rect (Screen.width - (Screen.width/2)-200,Screen.height - (Screen.height/2)-350,700,550),questionBoard);
GUI.Label (Rect (Screen.width - (Screen.width/2)+10,Screen.height - (Screen.height/2)-250,700,550),questions[currentQuestion][0]);
GUI.Box (Rect (Screen.width - (Screen.width/2)-60,Screen.height - (Screen.height/2)-55,300,40), questions[currentQuestion][1]);
GUI.Box (Rect (Screen.width - (Screen.width/2)-60,Screen.height - (Screen.height/2)+10,300,40), questions[currentQuestion][2]);
GUI.Box (Rect (Screen.width - (Screen.width/2)-60,Screen.height - (Screen.height/2)+80,300,40), questions[currentQuestion][3]);
//GUI.Label (Rect (85,240,4000,20), questions[currentQuestion][4]);
///// wINNER!
if(winnerBanner)
{
GUI.Label (Rect (155,150,4000,20),"End of game " + currentPlayer + " Congratulations with ");
}
//// wINNER!
// Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
if (GUI.Button (Rect (Screen.width - (Screen.width/2)-72,Screen.height - (Screen.height/2)-60,60,40)," "))
{
answerMark = 1;
if(questionAllUsed)
{
lastQuestionDone = true;
}
if(questions[currentQuestion][5] == "1")
{
continueCorrectButton = true;
}
else
{
continueIncorrectButton = true;
}
}
// Make the second button.
if (GUI.Button (Rect (Screen.width - (Screen.width/2)-72,Screen.height - (Screen.height/2),60,40)," "))
{
answerMark = 2;
if(questionAllUsed)
{
lastQuestionDone = true;
}
if(questions[currentQuestion][5] == "2")
{
continueCorrectButton = true;
}
else
{
continueIncorrectButton = true;
}
}
// Make the third button.
if (GUI.Button (Rect (Screen.width - (Screen.width/2)-72,Screen.height - (Screen.height/2)+72,60,40)," "))
{
answerMark = 3;
if(questions[currentQuestion][5] == "3")
{
continueCorrectButton = true;
}
else
{
continueIncorrectButton = true;
}
}
if( lastQuestionDone )
{
if(playerOnePoints > playerTwoPoints)
{
winnerBanner = true;
finalScore = playerTwoPoints;
}
if(playerTwoPoints > playerOnePoints)
{
winnerBanner = true;
finalScore = playerTwoPoints;
}
if(playerOnePoints == playerTwoPoints)
{
winnerBanner = true;
finalScore = playerTwoPoints;
}
}
else
{
if(initialButton == false && continueCorrectButton== false && continueIncorrectButton== false)
{
GUI.Label (Rect (25,500,4000,20),"Player Turn: " + currentPlayer);
GUI.Label (Rect (25,100,4000,20),"Player 2 Score " + playerTwoPoints);
GUI.Label (Rect (25,50,4000,20),"Player 1 Score " + playerOnePoints);
questionCheck = 0;
while(questions[currentQuestion][6] == "1")
{
currentQuestion = parseInt(Random.Range(0,numOfQuestions-1));
if(questionCheck > numOfQuestions*2)
{
keepGoing = true;
for(n = 0; n < numOfQuestions && keepGoing; n++)
{ Debug.Log(n + "NNNNNNNN");
if( questions[n][6] == "0")
{
currentQuestion = n;
n = numOfQuestions;
keepGoing=false;
}
}
if(n > numOfQuestions)
{
questionAllUsed = true;
}
}
questionCheck++;
} }
}
if(answerMark == 1)
{
GUI.Label (Rect (Screen.width - (Screen.width/2)-53,Screen.height - (Screen.height/2)-67,60,40), goldStar);
}
if(answerMark == 2)
{
GUI.Label (Rect (Screen.width - (Screen.width/2)-53,Screen.height - (Screen.height/2)-6,60,40), goldStar);
}
if(answerMark == 3)
{
GUI.Label (Rect (Screen.width - (Screen.width/2)-53,Screen.height - (Screen.height/2)+63,60,40),goldStar);
}
}
}
if(escHit == true){
//Backround for Exit Menu
GUI.Box (Rect ((Screen.width/2)-100,(Screen.height/2)-25,300,100), "");
}
// Clicking exit button
if(escHit == true && GUI.Button (Rect ((Screen.width/2),(Screen.height/2),100,50), "Quit"))
{
Application.Quit();
}
}
function Update()
{
if( startGame == false)
{
// currentPlayer 1
if (lastQuestionDone == false)
{
if( currentPlayer == 1 )
{
if(move != 0)
{
//showQuestion = false;
currentPlayer = 2;
move = 0;
}
}
//currentPlayer 2
if( currentPlayer == 2 )
{
if(move != 0)
{
//showQuestion = false;
currentPlayer = 1;
move = 0;
}
}
}
else
{
}
if(Input.GetKeyDown(KeyCode.Escape) && escTimer > 20)
{
escTimer = 0;
escHit = !escHit;
scripts = !scripts;
//Camera.main.GetComponent(Movementtest1).enabled = scripts;
}
else
{
escTimer += 1;
}
}
}