Hello everyone, i need 3 instances of an object at 3 different positions on the x axis between x = - 4 and x = 4. Then in another script, i need these 4 objects to start a ping pong movement along the x axis. So it seems i need a static array variable. I created this code but unity gives me lots of errors. Can you help me?
Script 1 (named GameController.js)
static var xpos : float[];
function Start(){
xpos = Random.Range (-4.0, 4.0);
}
function LevelEnd(){
Instantiate(enemy, Vector3(xpos[0], 0, 0), transform.rotation);
Instantiate(enemy, Vector3(xpos[1], 0, 0), transform.rotation);
Instantiate(enemy, Vector3(xpos[2], 0, 0), transform.rotation);
}
Script 2 (named EnemyMovement.js)
var pingpongspeed: float;
function Update () {
GameController.xpos += Time.deltaTime*pingpongspeed;
transform.position.x = Mathf.PingPong (GameController.xpos, 8.0);
}