How to make shapes move forward when they instantiate in Javascript?

I have a timer script which increases the speed of an object after a second has gone by. My shape behavior script calls this script and applies it to itself so that anytime another shape spawns it doesn’t start at the lowest speed but from where the timer left off. Problem is, anytime a shape appears, it simply remains frozen in place. I’m really having trouble figuring this out, and would very much appreciate the help!

There is an Instantiate script applied to three “spawner” objects in the hierarchy which calls the shape prefabs to instantiate and point towards the player. This is working just fine. There is a Timer script which is applied to the groundplane and tracks time and increases the speed variable as time goes on, and finally there is a Shape Behavior script which is applied to the shape prefabs, calls on both the Instantiate and Timer scripts and enables them to get destroyed when clicked on and should enable them to move towards the player at an accelerated rate (which isn’t working). I’ll attach the Timer and ShapeBehavior scripts.

Timer

#pragma strict

public var time : float;
public var speed : float;

function Start()
{
	speed = 0.1;
}

function Update()
	
{
	time += Time.deltaTime;
	if (time > 1)
	{
		speed += 0.01;
		time = 0;
	} 
	
}

ShapeBehavior

#pragma strict

var Player : GameObject;
var sound : AudioSource;
var TimeManager : GameObject;
var ShapeSpeed : float;




function Start()
{
	ShapeSpeed = TimeManager.GetComponent(Timer).speed;
	
}

function Update()
{
	transform.Translate(0, 0, ShapeSpeed);
	Debug.Log(ShapeSpeed);
	
}



function OnMouseDown() 
{
	sound.audio.Play();
	Player.GetComponent(Player_Script).score = Player.GetComponent(Player_Script).score + 15;
	yield WaitForSeconds(.11);
	Destroy(gameObject);
}

The problem with your code is that ShapeSpeed is only set once in the Start function of the ShapeBehaviour class. you need to be updating that variable each frame, so move this line of code

ShapeSpeed = TimeManager.GetComponent(Timer).speed;

into the Update statement and it should work.

Thank you for the suggestion, however I still seem to be faced with the same issue…

Can you explain what exactly is not working, the moving towards the player or the acceleration or both? Cause another thing I dont see in your code is that the Shape script does not LookAt the player transform

I didn’t read your code but generally the answer is: http://unity3d.com/learn/tutorials/modules/beginner/physics/addforce

The LookAt function is added in a different script. Here it is:

#pragma strict

var go = new GameObject[3];
var cube_prefab : GameObject;
var sphere_prefab : GameObject;
var cylinder_prefab : GameObject;
var target : Transform;

InvokeRepeating("Spawn", 1, 3);

function Start()
{
	go[0] = cube_prefab;
	go[1] = sphere_prefab;
	go[2] = cylinder_prefab;
	
	transform.LookAt(Vector3(target.transform.position.x, transform.position.y, target.transform.position.z));
	
}

function Spawn()
{
	var instance : GameObject = Instantiate(go[Random.Range(0,3)], transform.position, transform.rotation);	
}

This along with a Vector3.forward script seemed to make it work just fine, though the issue was that it accelerated until it was destroyed and then went back to the original speed. Since I wanted the speed to constantly go up as time when on no matter how many shapes instantiated, I was told I could make a separate “universal” timer to control that. It seems to show that the speed goes up in the timer script, but the problem is, any time a shape instantiates it remains frozen in place.

Thank you, I’ll check it out.