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
0
Question by Psycho8Vegemite · Jun 29, 2014 at 03:00 PM · c#errorarrayfloatfor-loop

Array error, cannot convert float to float[] ????

Yeah, the tittle pretty much explains it. I have three arrays that goes towards collecting data from different light components found on another array, but when trying to assign these values to the three arrays of the Lights it tells me this...

error CS0029: Cannot implicitly convert type UnityEngine.Color' to UnityEngine.Color[]’ line 71 error CS0029: Cannot implicitly convert type float’ to float[]’ lines 72 and 73 x2

So what I’m asking is, what am I doing wrong or what’s a way around this to still get what I want done? Here’s the code where it is going wrong with the for loop and all, thanks in advace:

 using UnityEngine;
 using System.Collections;
 
 public class LightFlickerPulse : MonoBehaviour {
 
     public enum UseType {Color, Intensity, Range, Off}
     public UseType useType;
     public enum WaveFunction {Noise, Sin, Tri, Sqr, Saw, SawInv}
     public WaveFunction waveFunction;
 
 
     public float timescaleMinWorking = 0.1f;
 
     public float coreBase = 0.8f;
     public float amplitude = 0.4f;
     public float phase;
     public float frequency = 0.5f;
 
     public bool useOutsideLight;
     public Light[] outsideLight;
 
     private Color mainColor;
     private float mainValueI;
     private float mainValueR;
     
     private Color[] mainOutColor = new Color[50];
     private float[] mainOutValueI = new float[50];
     private float[] mainOutValueR = new float[50];
 
     private Light lightS;
 
     private bool error1;
     private bool error2;
     private bool assigned;
 
     private float x;
     private float y;
     private float z;
 
 
 
     void Update(){
         if(lightS == null){
             if(useOutsideLight){
                 lightS = outsideLight[1];
             }else{
                 lightS = gameObject.light;
             }
         }
         if(!assigned){
             if(GetComponent<Light>() != null){
                 mainColor = light.color;
                 mainValueI = light.intensity;
                 mainValueR = light.range;
                 if(error1){
                     Debug.Log ("FIXED ERROR REPORT: The missing Light component on the gameObject " + "'" +gameObject.name + "'" + " has been succesfully re-established!", gameObject);
                     error1 = false;
                 }
                 assigned = true;
             }else if(!error1){
                 Debug.LogError ("ERROR MISSING COMPONENT: The gameObject " + "'" +gameObject.name + "'" + " does not have a Light component attached to it. If you wish to use a Light from another gameObject, please select the boolean variable 'Use Outside Light' for this feature.", gameObject);
                 error1 = true;
             }
             if(outsideLight.Length > 0 && outsideLight.Length < 50){
                 for(int i = 0; i < outsideLight.Length; i++){
                     if(outsideLight[i] == null){
                         error2 = true;
                         Debug.LogError ("ERROR EMPTY VARIABLE: The gameObject " + "'" +gameObject.name + "'" + " does not have a gameObject with a Light component attached to the variable 'Outside Light' index number " + "[ " + i + " ], to fix this either, assign a gameObject with a Light component in this space or, lowwer the size amount to fix your assigned lights. If you do not wish to use this feature, un-tick the boolean variable 'Use Outside Light.'", gameObject);
                         Debug.LogError ("VARIABLE ADDITIONAL INFORMATION: This feature does not allow for fixing after the error has occured due to strict limintations of the 'for' loop, you must replay with the Light component attached to the variable 'Outside Light' index number " + "[ " + i + " ], correctly.", gameObject);
                     }else{
                         mainOutColor = outsideLight[i].color;
                         mainOutValueI = outsideLight[i].intensity;
                         mainOutValueR = outsideLight[i].range;
                     }
                 }
                 if(!error2){
                     assigned = true;
                 }
             }else if(!outsideLight.Length < 50){
                 Debug.LogError ("ERROR EXCEDING ARRAY LIMITATIONS: Due to this script having to pre-load other array variables to gather all the Light components information a desision was made on how many arrays as max should be pre-defined to remove any performance issues. To fix this error you could modify this script to allowcate more avaliable spots located in the defining variables section or remove some or many Light components from the array list on the gameObject " + "'" +gameObject.name + "'. The defined Light components past the 49th index number will not work under this script.", gameObject);
             }
         }
         if(((!error1 && !useOutsideLight) || (!error2 && useOutsideLight)) && assigned && useType != UseType.Off && Time.timeScale > timescaleMinWorking){
             CalWaveFunc();
             if(useType == UseType.Color){
                 lightS.color = mainColor * (z);
             }else if(useType == UseType.Intensity){
                 lightS.intensity = mainValueI * (z);
             }else if(useType == UseType.Range){
                 lightS.range = mainValueR * (z);
             }
         } 
         if(lightS != null){
             if(mainValueI != lightS.intensity && (useType != UseType.Intensity)){
                 lightS.intensity = mainValueI;
             }
             if(mainValueR != lightS.range && (useType != UseType.Range)){
                 lightS.range = mainValueR;
             }
             if(mainColor != lightS.color && (useType != UseType.Color)){
                 lightS.color = mainColor;
             }
         }
     }
 
 
 
     void CalWaveFunc(){
 
         x = (Time.time + phase)*frequency;
         x = x - Mathf.Floor(x);
 
         if(waveFunction == WaveFunction.Sin){
             y = Mathf.Sin(x*2*Mathf.PI);
         }else if(waveFunction == WaveFunction.Tri){
             if(x<0.5f){
                 y=4.0f*x-1.0f;
             }else{
                 y=-4.0f*x-3.0f;
             }
         }else if(waveFunction == WaveFunction.Sqr){
             if(x<0.5f){
                 y=1.0f;
             }else{
                 y=-1.0f;
             }
         }else if(waveFunction == WaveFunction.Saw){
             y=x;
         }else if(waveFunction == WaveFunction.SawInv){
             y=1.0f-x;
         }else if(waveFunction == WaveFunction.Noise){
             y=1-(Random.value*2);
         }
         z = (y*amplitude)+coreBase; 
     }
 }
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 NoseKills · Jun 29, 2014 at 03:06 PM 0
Share

Are you possibly doing sometging like `Color[] mainOutColor = new Color(); ?

avatar image Psycho8Vegemite · Jun 29, 2014 at 03:35 PM 0
Share

Yeah, the full script has been updated. I did that beforehand to pre-load with 50 indexes.

2 Replies

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

Answer by tanoshimi · Jun 29, 2014 at 03:39 PM

Yep, there's your problem:

 private Color[] mainOutColor = new Color[50];
 ...
 mainOutColor = outsideLight[i].color;

mainOutColor, mainOutValueI, and mainOutValueR are arrays, but you're trying to assign a single value to them.

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 Psycho8Vegemite · Jun 29, 2014 at 03:47 PM 0
Share

Wow, how did I not notice that. I think I should stop drinking coffee and get some sleep for a while haha. Thank you man!

avatar image
0

Answer by Jeff-Kesselman · Jun 29, 2014 at 03:01 PM

It means that the left hand of one of your assignments is defined as a float array but you are trying to put a float value in it.

without seeing the entire error message and the entire code file, its impossible to say more.

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 Psycho8Vegemite · Jun 29, 2014 at 03:33 PM 0
Share

It’s been updated showing the full code, the problem’s at lines 71, 72 and 73. And thats all the error message said, without the directories.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

convert object to float 2 Answers

Error CS0029 Help? (Screenshot of Exact Error) 1 Answer

Strange behaviour with List C# 0 Answers

Unexpected symbol 'Flip' and 'else' 1 Answer

how can i check if index exists? 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