I need help. I cant seem to make a cube move randomly inside a certain area. I also need help being to click on that cube and have its renderer disabled after two clicks and a explosion effect happen as well as a random respawn time and 1 point added to the score. I have many scripts but after 10+ hours of trying I continue to fail. I have a strong feeling I will never be a good programmer :'(. I have spent countless hours watching and reading tutorials, and to fail so much :(. I will post codes and where they are attached.
var start : Transform;
var end : Transform;
var shapeColor : Color[]; // color of the object
var numberOfClicks : int = 2;
var explosion : Transform;
private var storeClicks : int = 0;
function Start ()
{
storeClicks = numberOfClicks;
RandomColor ();
}
function Update ()
{
transform.Translate (start.position * 0.01);
if (numberOfClicks <= 0)
{
RespondWaitTime();
numberOfClicks = storeClicks;
}
}
function RandomColor ()
{
if (shapeColor.length > 0)
{
var newColor = Random.Range(0, shapeColor.length);
renderer.material.color = shapeColor[newColor];
}
}
function RespondWaitTime ()
{
var respawnWait = Random.Range(Random.Range(0,1), Random.Range(3,4));
if (explosion)
{
Instantiate (explosion, transform.position, transform.rotation); // create an explosion
}
renderer.enabled = false;
yield WaitForSeconds (respawnWait);
var position = Vector3 (Random.Range(-6,6),Random.Range(-4,4),0); // new random position for the gameObject
transform.position = position; // move the gameObject to a random position
renderer.enabled = true;
}
// Player Script
// Inspector Variables
var tagNameTwo : String;
var tagName : String; //allow the designer to setup a tag in the inspector
var rayDistance : float = 0; //length of the ray for out raycast
var score : int = 0; //score for our player
var gameTime : float = 5; //amount of time the game will last
var loadWaitTime : float = 3.0;
var numberOfPointsToWin : int = 5; //amount of points needed to win
// Private Variables
//
function Start()
{
InvokeRepeating("CountDown", 1.0, 1.0); // Repeat the countdown every second
}
// Update is called every frame
function Update ()
{
// use the mouse button to select onGO in the scene
if (Input.GetMouseButtonDown(0))
{
audio.Play();
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition); // get mouse position
if (Physics.Raycast (ray, hit, rayDistance))
{
if (hit.transform.tag == tagName)
{
//var position = Vector3 (Random.Range(-6,6),Random.Range(-4,4),0); // new random position for the gameObject
//hit.transform.position = position; // move the gameObject to a random position
var enemyScript = hit.transform.GetComponent(scriptEnemy);
enemyScript.numberOfClicks -= 1;
if(enemyScript.numberOfClicks == 0)
{
score += enemyScript.enemyPoints;
}
}
if (hit.transform.tag == tagNameTwo)
{
var moveScript = hit.transform.GetComponent(scriptMove);
moveScript.numberOfClicks -= 1;
if (moveScript.numberOfClicks == 0)
{
score ++;
}
}
}
}
}
function CountDown()
{
if (--gameTime == 0) // subtract from gametime
{
CancelInvoke("CountDown"); // cancell the countdown
//yield WaitForSeconds (loadWaitTime);
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);
}
function Start ()
{
//InvokeRepeating ("MoveIt", 1, 10);
var position = Vector3 (Random.Range(-6,6),Random.Range(-4,4),0); // new random position for the gameObject
transform.position = position;
}
function MoveIt()
{
var position = Vector3 (Random.Range(-6,6),Random.Range(-4,4),0); // new random position for the gameObject
transform.position = position;
}