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 /
avatar image
-1
Question by Square Monkey · Jan 30, 2014 at 11:57 PM · c#errormenuslider

Menu Building - Cannot implicity convert type float to int

Back again with a new noobie question.

So I'm building this main menu Rust style and I found a quality slider code for my options menu. Totally overjoyed I copy pasted it in my code to find the error stated below. If someone could point out the error and explain WHY this keeps happening you will probably never see this question again! Thank you in advance! Code btw is in C#

Error

 Assets/Scripts/mainMenuSliderScaleable.cs(68,49): error CS0266: Cannot implicitly convert type `float' to `int'. An explicit conversion exists (are you missing a cast?)

Code using UnityEngine; using System.Collections;

 public class mainMenuSliderScaleable : MonoBehaviour
 {
         //resolution settings
         public float originalWidth = 1024.0f;
         public float originalHeight = 768.0f;
         private Vector3 scale;
         //scrollbar settings
         public Vector2 scrollPosition;
         //menu settings
         public bool showOptions = false;
         public bool showCredits = false;
         public Texture2D MyTexture;
         //video settings
         public int gameQuality = 0;
         //audio settings
         public float masterVolume = 100.0f;
         public float musicVolume = 100.0f;
         public float SFXVolume = 100.0f;
     
         void Update ()
         {
                 AudioListener.volume = musicVolume / 100.0f;
         }
     
         void OnGUI ()
         {
                 scale.x = Screen.width / originalWidth;
                 scale.y = Screen.height / originalHeight;
                 scale.z = 1;
                 var svMat = GUI.matrix;
                 GUI.matrix = Matrix4x4.TRS (Vector3.zero, Quaternion.identity, scale);
                 //GUI.Box (new Rect (0, 0, Screen.width, Screen.height));
         
                 GUILayout.BeginArea (new Rect (20, Screen.height / 2 - 50, 200, 100));
                 GUILayout.BeginVertical ();
         
                 if (GUILayout.Button ("Start Game")) {
                         Application.LoadLevel (4);
                 }
                 if (GUILayout.Button ("Options")) {
                         showOptions = true;
                         showCredits = false;
                 }
                 if (GUILayout.Button ("Credits")) {
                         showCredits = true;
                         showOptions = false;
                 }
                 if (GUILayout.Button ("Quit Game")) {
                         Application.Quit ();
                 }
         
                 GUILayout.EndVertical ();
                 GUILayout.EndArea ();
         
                 if (showOptions == true) {
                         GUILayout.BeginArea (new Rect (300, 50, 600, 800));
                         //scrollbar
                         scrollPosition = GUILayout.BeginScrollView (scrollPosition, GUILayout.Width (600), GUILayout.Height (600));
                         //video
                         //quality
                         GUILayout.Label ("Video Settings", GUILayout.Width (100));
                         GUILayout.BeginHorizontal ();
                         GUILayout.Label ("Quality", GUILayout.Width (100));
                         GUILayout.BeginVertical ();
                         gameQuality = GUILayout.HorizontalSlider (gameQuality, 0, 5,GUILayout.Width(150), GUILayout.Height(35));
                         QualitySettings.SetQualityLevel (gameQuality);
 
                         GUILayout.EndVertical ();
                         GUILayout.EndHorizontal ();
                         //resolution
                         GUILayout.Label ("", GUILayout.Width (100));
                         //800x600
                         //1024x768
                         //1366x768
                         //1920x1080
                         //audio
                         GUILayout.Label ("Audio Settings", GUILayout.Width (100));
                         GUILayout.Label ("Master Volume", GUILayout.Width (100));
                         masterVolume = GUILayout.HorizontalSlider (masterVolume, 0.0f, 100.0f);
                         GUILayout.Label ("Music Volume", GUILayout.Width (100));
                         musicVolume = GUILayout.HorizontalSlider (musicVolume, 0.0f, 100.0f);
                         GUILayout.Label ("Effects Volume", GUILayout.Width (100));
                         SFXVolume = GUILayout.HorizontalSlider (SFXVolume, 0.0f, 100.0f);
                         //controller
                         GUILayout.Label ("Control Controls", GUILayout.Width (100));
                         GUILayout.Label ("Move Controls", GUILayout.Width (100));
                         GUILayout.Label ("Look Controls", GUILayout.Width (100));
                         GUILayout.Label ("Interaction Controls", GUILayout.Width (100));
             
                         GUILayout.EndScrollView ();
                         GUILayout.EndArea ();
 
                         GUI.matrix = svMat;
                 }
         }
 }
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 getyour411 · Jan 30, 2014 at 11:58 PM 0
Share

When you post code, especially code that's referencing an error and a line# at least format all the code so the two line-up. As is they are off cuz you didn't include all your code in your formatting

avatar image Square Monkey · Jan 31, 2014 at 02:44 AM 0
Share

lol As I am pretty new to unity answers it's pretty harsh that you already flame me for a mistake. However my problem is still there.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by chaos_technician · Feb 05, 2014 at 07:46 AM

That error means that you're calling a function or operator that expects an integer type, but you're supplying a float instead. It looks to me like the issue is on this line:

 gameQuality = GUILayout.HorizontalSlider (gameQuality, 0, 5,GUILayout.Width(150), GUILayout.Height(35));

In your code, gameQuality is an integer, whereas GUILayout.HorizontalSlider returns a float. You need to cast the result from GUILayout.HorizontalSlider to an int when assigning it to gameQuality.

 gameQuality = (int)GUILayout.HorizontalSlider (gameQuality, 0, 5,GUILayout.Width(150), GUILayout.Height(35));
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.

Follow this Question

Answers Answers and Comments

19 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Horizontal Slider with Labels 3 Answers

How to make a slider menu 1 Answer

"NullReferenceException: Object reference not set to an instance of an object" with instantiate C# 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