Operator issue!

Hello,

I don’t know what causes this maybe its just a bug, but I keep getting this error message.

BCE0051: Operator ‘-’ cannot be used with a left hand side of type ‘float’ and a right hand side of type ‘Object’.

Here is my code;

var SpawnPrefab:Transform;
private var startTime;

function Awake()
{
startTime = Time.time;
}

function Update ()
{

var elapsedTime= Time.time - startTime;
SpawnPrefab=Instantiate(SpawnPrefab,this.transform.position, this.transform.rotation);

}

You haven’t declared the type of the “startTime” variable.

–Eric

Thanks for the reply error is gone. But I have another behaviour problem.

I have this code to create an object for every second.
Problem is when the elapsedTime reaches 1, it constantly creates the same object. I reset the elapsedTime, but it doesn’t seem to work.

var SpawnPrefab:Transform;
private var startTime:float;
private var elapsedTime:float;
function Awake()
{
startTime = Time.time;
}

function Update ()
{

//var elapsedTime= Time.time - startTime;
elapsedTime=Time.time - startTime;
//if(Input.GetButtonDown(“test”))
if(elapsedTime > 1)
{
var SpawnPrefab=Instantiate(SpawnPrefab,this.transform.position, this.transform.rotation);
elapsedTime=0;
}

Debug.Log(elapsedTime);
}

Thank you

OK. I fixed the problem I forgot to call Awake() function inside the update.

you don’^t need to call awake, thats called itself when the object is created.

but thats potentially the problem as well, it happens potentially much earlier than update. You would potentially want to do it in start.