Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Rebel8909 · Dec 13, 2015 at 05:29 AM · javascripttime

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;
             }
         }
     }
 }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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;
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Rebel8909 · Dec 13, 2015 at 04:01 PM 1
Share

Thank you, that seems to have fixed it!

avatar image dhore Rebel8909 · Dec 14, 2015 at 12:51 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

38 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges