• 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 /
avatar image
0
Question by adel22 · Jan 01, 2012 at 08:58 AM · compiler-error

compiler error.

when i try to enter play mode in unity, it gives me an error saying that i need to fix the compiler error. so I go into console and this is the error: Assets/Scripts/UnderwaterEffects.js(23,46): BCE0022: Cannot convert 'UnityEngine.GameObject' to 'float'. How do i fix this error in the script? help would be greatly appreciated, please take in mind that i am new to unity. Thanks for the support.

Comment
Add comment · Show 2
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 BiG · Jan 01, 2012 at 10:19 AM 1
Share

We have to look at your code, to help you out.

avatar image adrenak · Jan 01, 2012 at 01:37 PM 0
Share

check your variables, specially the GameObject type

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by aldonaletto · Jan 01, 2012 at 03:32 PM

It's a known problem with the old Island Demo script (one of them - there are lots of other bugs!) - it was written for Unity 2.x, and doesn't work in Unity 3.x.
This error occurs because line 23 tries to assign water.gameObject to the float waterLevel (no idea on how this could have ever worked in any Unity!):

   if(water) waterLevel = water.gameObject;

You can fix this error by simply changing line 23 to this:

   if (water) waterLevel = water.transform.position.y;

But this doesn't solves all the problems: the script UpdateTreeColors.js will give two errors, in lines 13 and 31; just place a comment signal (//) in front of each of these lines to comment them out, and the Island Demo should compile and work (at least in Unity Free; maybe other errors arise in the Pro version.)

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 adel22 · Jan 01, 2012 at 05:21 PM 0
Share

thank you aldonaletto, I did what you suggested and it did solve the problem, except now i have a new compiler error: Assets/Scripts/UnderwaterEffects.js(14,1): BCE0043: Unexpected token: private. its on line 14 "private var below = false;" thanks for your help.,thanks i did what you suggested, and it worked. but now i have a new compiler error: Assets/Scripts/UnderwaterEffects.js(14,1): BCE0043: Unexpected token: private. The error is on line 14. Thanks for all your help.

avatar image aldonaletto · Jan 01, 2012 at 05:27 PM 0
Share

You may have deleted something above this line - a ";" character, for instance. Check if there's something wrong with the first script lines - they should be like this:

var waterLevel : float; var uAudio : AudioClip; var aAudio : AudioClip;

var uColor = Color(1,1,1,1); var uDensity = .05;

var aColor = Color(1,1,1,1); var aDensity = .008;

var waterSurface : Renderer; var underwaterSurface : Renderer;

private var below = false; ...

avatar image
0

Answer by SergeyLavren · Jan 01, 2012 at 04:33 PM

You probably tries to assign Object type to primitive type, i.e. GameObject to some float variable. This is not possible. Probably misspelled or copypasted.

Comment
Add comment · 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
0

Answer by Kaze_Senshi · Jan 01, 2012 at 03:07 PM

You should be using a variable that is of a "GameObject" type as a float. For example:

 function OnCollisionStay(collisionInfo : Collision) 
 {
     var platformerController : PlatformerController = collisionInfo.gameObject; //Getting a gameObject
     var x : float = 10.0 + platformerController; //and using it in a arithmetic operation
 }
Comment
Add comment · 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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

9 People are following this question.

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

Related Questions

how do i fix this error? 1 Answer

How do i fix this error? Okay, when i create any kind of script, i get this error in the console log: 1 Answer

Unity 2018.3 + Visual Studio 2015 -> Invalid "latest" for /langversion 1 Answer

How do I fix compliance error? 1 Answer

static function generates error CS0119: 1 Answer


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