- Home /
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;
}
}
Are you possibly doing sometging like `Color[] mainOutColor = new Color(); ?
Yeah, the full script has been updated. I did that beforehand to pre-load with 50 indexes.
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.
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!
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.
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
Follow this Question
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