Hi, sorry again for my noobish question but im not sure why it is not working. Basically im on walkerboystudio lab 1:
http://www.walkerboystudio.com/html/unity_course_lab_1.html
i’ve finished the video but im confused what to do to finish the lab…
First of all, this is the original code for scriptEnemy.js:
var numberOfClicks : int = 2;
var respawnWaitTime : float = 2.0;
var shapeColor : Color[];
var explosion : Transform;
var enemyPoint : int = 1;
private var storeClicks : int = 0;
function Start ()
{
storeClicks = numberOfClicks;
var startPosition = Vector3 (Random.Range(-6,6), Random.Range(-4,4), 0);
transform.position = startPosition;
RandomColor ();
}
function Update () {
if (numberOfClicks <= 0)
{
if (explosion)
{
Instantiate (explosion, transform.position, transform.rotation);
}
if (audio.clip)
{
audio.Play();
}
var position = Vector3 (Random.Range(-3,3),Random.Range(-3,3), 0);
WaitTime();
transform.position = position;
numberOfClicks = storeClicks;
}
}
function WaitTime ()
{
renderer.enabled = false;
RandomColor();
yield WaitForSeconds (respawnWaitTime);
renderer.enabled = true;
}
function RandomColor ()
{
var newColor = Random.Range(0, shapeColor.length);
renderer.material.color = shapeColor[newColor];
}
this script aboveis applied to the “sphere”…there’s also one object called playerObject which applied with scriptPlayer.js, and here is what’s inside scriptPlayer:
var tagName : String;
var rayDistance : float = 0;
var score : int = 0;
var gameTime : float = 5.0;
var loadWaitTime : float = 3.0;
var waitbefore : float = 4.0;
var numberOfPointsToWin : int = 5;
function Start ()
{
InvokeRepeating ("CountDown", 1.0, 1.0); // start the timer countdown
}
function Update ()
{
if (Input.GetMouseButtonDown(0))
{
anjing2();
print ("It works!");
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(scriptEnemy);
enemyScript.numberOfClicks -= 1;
if (enemyScript.numberOfClicks == 0)
{
score += enemyScript.enemyPoint;
}
}
else
{
print ("This is not an enemy!");
}
}
}
}
function CountDown ()
{
if (--gameTime == 0) // gametimer will keep reducing until 0
{
CancelInvoke("CountDown"); // to cancel the invoke when it reaches 0
if ( score >= numberOfPointsToWin )
{
Application.LoadLevel ("sceneScreenWin");
}
else
{
Application.LoadLevel ("sceeneScreenLose");
}
}
}
function OnGUI ()
{
GUI.Label (Rect(10,10,100,20), "Score: " + score);
GUI.Label (Rect(10,20,100,20), "Time: " + gameTime);
}
function anjing2 ()
{
yield WaitForSeconds (waitbefore);
}
Now they told me to do this by myself:
How can i do that? i have tried to add another function, similar to “WaitTime ()”, i called it “WaitTime2 ()”, and use differet variable name for it. I added WaitTime2(); above if explosion() in scriptEnemy.js, but it doesn’t work?