Cannot use a '>' with a left hand side of type 'float' and a right hand side of type 'Object'?
So I'm fiddling around with a project and I need a delay between when the player clicks on an object to pick it up, and clicking again to set it back down. I looked it up using a delay and found this bit of code
var nextUse;
var delay = 1;
function Start (){
nextUse = Time.time + delay;
}
function Update(){
if(Time.time > nextUse){
nextUse = Time.time + delay;
...do stuff...
}
}
I tried using this and sorta got it to work once but only for the first click, before I noticed I hadn't added the nextUse = Time.time + delay; after if statement. However it started giving me the "Cannot use a '>' with a left hand side of type 'float' and a right hand side of type 'Object' " error. I tried getting rid of the bit I added but the problem persists. Here's my actual code if it'll help.
#pragma strict
//==========================================================================================================================//
var mstrCtrl : GameObject;
var selected : GameObject; //should set to whatever game object gets clicked on and move it
var selectedOn : boolean;
//var ConnectorControl = GetComponent(Connector_Controller);
var nextUse;
var delay = 1; //seconds delay
//=========================================================================================================================//
function Start () {
nextUse = Time.time + delay;
mstrCtrl = this.gameObject;
DontDestroyOnLoad (mstrCtrl);
selectedOn = false;
selected = null;
}
function Update () {
var V3T = Vector3(Input.mousePosition.x, Input.mousePosition.y, 10);
V3T = Camera.main.ScreenToWorldPoint(V3T);
if(selectedOn == false){
if (Time.time > nextUse){
if(Input.GetMouseButtonDown(0)){
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, hit)){
if(hit.collider/*.tag == "Atom"*/){
selected = hit.collider.gameObject;
selectedOn = true;
Debug.Log(GameObject);
}
}
}
}
}
if(selectedOn == true){
selected.transform.position = V3T;
if(Time.time > nextUse){
nextUse = Time.time + delay;
if(Input.GetMouseButtonDown(0)){
selected = null;
selectedOn = false;
}
}
}
}
Answer by dhore · Dec 13, 2015 at 06:35 AM
I think it may be picking up nextUse
as a generic object since you didn't actually specify what type of variable it was when you declared it. Try changing the declaration of that variable to this:
var nextUse : float;
No worries :) Glad I could help.
Also, if you could mark my answer as correct that'd help a lot so everyone knows your question is answered. Cheers.
Your answer
Follow this Question
Related Questions
How do I fix the following error? 1 Answer
How to execute code after X seconds 2 Answers
Storing timetstamp when building for WebGL with C# 0 Answers
How to make sprites bounce? 0 Answers
Expecting EOF found 'Public' 2 Answers