Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Jul 02, 2014 at 01:34 PM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by seb-lopez · Apr 25, 2014 at 02:41 AM · erroraibasicbce0051

BCE0051: Operator '<' cannot be used with a left hand side of type 'Object' and a right hand side of type 'float' !!!

hello , im doing a Ai script that when you approche to the gameObject it will start following you ( i'm sure it's a classic basic script for Pro's ;) ) but im get tree same Errors: -BCE0051: Operator '<' cannot be used with a left hand side of type 'Object' and a right hand side of type 'float'

in line 29.22 in line 36.22 and in line 42.22

 pragma strict
  var Distance;
 var lookAtDistance : float = 25;
 var attackRange : float = 15;
 var animator : Animator;
 
 var target : Transform; 
 var moveSpeed : float= 0;
 var rotationSpeed: float = 1; 
 
 private var myTransform : Transform; //current transform data of this enemy
 private var controller : CharacterController;
  
 function Awake()
 {
     myTransform = transform; //cache transform data for easy access/preformance
     controller = GetComponent(CharacterController); // cache the CharacterController
 }
  
 function Start()
 {
     target = GameObject.FindWithTag("Player").transform; //target the player
 }
  
 function Update () 
 {
 Distance = Vector3.Distance(target.position, transform.position);
     
     if (Distance < lookAtDistance)
     {
         animator.SetBool("idle" , true);
         animator.SetBool("walk" , false);
         
     }
     
     if (Distance > lookAtDistance)
     {
         animator.SetBool("idle" , true);
         animator.SetBool("walk" , false);
     }
     
     if (Distance < attackRange)
     {
         animator.SetBool("idle" , false);
         animator.SetBool("walk" , true);
         
     }
 
 
 
     // find the target direction:
     var dir: Vector3 = target.position - myTransform.position;
     dir.y = 0; // ignore height differences to avoid enemy tilting
     //rotate to look at the player
     myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(dir), rotationSpeed*Time.deltaTime);
     //move towards the player:
     controller.SimpleMove(myTransform.forward * moveSpeed);
 }

at first i thought puting float's would work on the variables but it don't please help me!!

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

  • Sort: 
avatar image
2
Best Answer

Answer by robertbu · Apr 25, 2014 at 02:43 AM

You did not give 'Distance' a type. Change line 2:

 var Distance : float;

Without implicitly or explicitly giving a variable a type, the variable will be of type 'object'. The compiler cannot compare something of type object with something of type float.

Comment
Add comment · Show 1 · 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 seb-lopez · Apr 25, 2014 at 02:38 PM 0
Share

oops this was quite emberassin for me Thank you very much =D !!

Follow this Question

Answers Answers and Comments

21 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

Related Questions

BCE0051: Operator '<' cannot be used with a left hand side of type 'Object' and a right hand side of type 'float'. 2 Answers

Very Basic Raycasting 2 Answers

Need help calling a variable from another C# script 1 Answer

A Very Unusual Error 0 Answers

What's wrong with my AI script. 3 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