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 /
avatar image
0
Question by zak666 · Jan 09, 2016 at 11:54 PM · scriptingproblem

Assets/Scripts/Racing System/RacerPositionObject.cs(27,1): error CS0029: Cannot implicitly convert type `float' to `bool'

Hey Gang, Want to show my Racers Position Above the racer. I have a Plane Above Each racer with a Texture Of Its osision on it. The idea being when the posision counter (a float in anoher script) changes, the texture changers to the apropriate texture showing the Racers Posisioning Status.

 using UnityEngine;
 using System.Collections;
 
 public class RacerPositionObject : MonoBehaviour {
 
 
     public Texture Sixth;
     public Texture Fith;
     public Texture Fourth;
     public Texture Third;
     public Texture Second;
     public Texture First;
     public Renderer rend;
 
 
     // Use this for initialization
     void Start () {
         rend = GetComponent<Renderer>();
 
     }
     
     // Update is called once per frame
     void Update () {
 
         // Change Hovering Object Texture Acourding to the Posision of this Racer.
 if(RacingSystem.RacerPotision = 1){rend.material.mainTexture = First;}
 if(RacingSystem.RacerPotision = 2){rend.material.mainTexture = Second;}
 if(RacingSystem.RacerPotision = 3){rend.material.mainTexture = Third;}
 if(RacingSystem.RacerPotision = 4){rend.material.mainTexture = Fourth;}
 if(RacingSystem.RacerPotision = 5){rend.material.mainTexture = Fith;}
 if(RacingSystem.RacerPotision = 6){rend.material.mainTexture = Sixth;}
 
 
 }
 
 
 }
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

Answer by Eno-Khaon · Jan 10, 2016 at 02:26 AM

"RacingSystem.RacerPotision"[sic] being a float is a little confusing, unless the granularity is actually factored in, but I'll simply work with it being a float in this case.

Therefore, the problem is much simpler. You're missing an '=' per if statement.

 // Right now...
 if(RacingSystem.RacerPotision = 1)
 
 // It Should be...
 if(RacingSystem.RacerPotision == 1)

Additionally, because the other conditions cannot be met simultaneously, each other number used (2-6) can instead be checked using:

 else if(RacingSystem.RacerPotision == 6)

However, because your positions are floating point values rather than integers, it might be prudent to improve the likelihood of a match, to avoid floating point imprecision:

 if(Mathf.Approximately(RacingSystem.RacerPotision, 1.0f))

Additionally, the textures themselves can be condensed down into an array to simplify the entire process further:

 public Texture[] Placement; // Replaces First through Sixth
 
 // ...
 void Update()
 {
     rend.material.mainTexture = Placement[(int)(RacingSystem.RacerPosition - 0.5f)]; // subtracting 0.5 to preserve current functionality with integer conversion truncation.
 }

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

32 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

Related Questions

problem with the jump code.. 1 Answer

Do asleep rigidbodies prevent from modifying its variables in runtime? 1 Answer

AssetDatabase class is missing 1 Answer

How to watch variables from another script efficiently? 1 Answer

Acces SceneView Settings programmatically 0 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