Been following a simple point and click tut, done everything just as he does, minus a comment here and there. My problem, is that when I try to change the variables in the inspector (gameTime and such) they don’t update/change when I click play. He changes the same variables and clicks play and they DO update. I’m at a loss, I’m completely new to javascript / coding in general, he is using 3.5 and I’m using the latest. I’ve tried messing with the code, but to no satisfactory results. If I could just get this problem and one or two other minor ones ironed out, I could call this “game” complete and move on to the next tut. Any help would be appreciated. As I understand it, they’re simply acting like they’re hardcoded. (Note: Before pasting the code I messed with it a tiny bit, changed values on var gameTime to 0 from 5 and other little things, it was all just from a higher number to 0 though, thought that maybe they had to be on 0 to be able to be changed in the inspector. Other than the actual values for the vars, it’s all as he has it. And it wasn’t working when the values were exactly the same.)
//Inspector Variables
var tagName :String; //allow designer to setup tag in inspector
var rayDistance :float = 0; //length of the ray for our raycast
var score :int = 0; //score for our player
var gameTime :float = 0; //the amount of time the game will last
var loadWaitTime :float = 0; //amount of time to wait before we load the next scene
var numberOfPointsToWin :int = 0; //number of points to win game
function Start()
{
InvokeRepeating ("CountDown", 1.0, 1.0); //repeat the countdown every second
}
//update is called every frame
function Update()
{
if(Input.GetMouseButtonDown(0))
{
print("Pressed left click.");
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if(Physics.Raycast(ray, hit, rayDistance))
{
if(hit.transform.tag == tagName)
{
var enemyScript = hit.transform.GetComponent(scriptActorEnemy);
enemyScript.numberOfClicks -= 1; //reduce the number each click
//check that the object is at 0 before adding the points to the score
if (enemyScript.numberOfClicks == 0)
{
score += enemyScript.enemyPoint; //add point to our overall score
}
}
else
{
print ("This is not an enemy!");
}
}
}
}
function CountDown()
{
if(--gameTime==0) //subtract from gametime
{
CancelInvoke("CountDown"); //cancel the countdown
if (score >= numberOfPointsToWin)
{
Application.LoadLevel ("sceneScreenWin");
}
else
{
Application.LoadLevel ("sceneScreenLose");
}
}
}
//
function OnGUI()
{
GUI.Label(Rect(10, 10, 100, 20), "Score: " + score);
GUI.Label(Rect(10, 25, 100, 35), "Time: " + gameTime);
}