Skip to main content
Added links.
Source Link
Vaillancourt
  • 16.4k
  • 17
  • 56
  • 61

The error

Cannot implicitly convert type 'float' to 'byte'. An explicit conversion exists (are you missing a cast?)

means that you try to assign a value for a type to another where information could be lost (generally).

A bytebyte can hold integer values from 0 to 255. Time.deltaTime is a floatfloat, and it can hold much more different values. The compiler cannot implicitly convert from float to byte because you would lose a lot of data, so it asks you to explicitly do the casting (i.e. "tell me you're sure you want to do this").

So to simply make the issue go away, you'd have to do somethingexplicitly convert the Time.deltaTime to byte like. this:

redcurrent = redcurrent + redtarget * (byte)Time.deltaTime; 

However, in this case, that's not what you want. You want to change the type of redtarget and others to float, because you'll have to take the floating point values in consideration in this current situation, whereas you could not with byte.

Only doing this, you'll get more type conversion errors when trying to create a Color32 object.

To do that, you cast the values when/where you need them:

theobject.GetComponent<Renderer>().material.SetColor( "_EmissionColor", new Color32( (float)redcurrent, (float)greencurrent, (float)bluecurrent, opacitytarget)) ; 

The error

Cannot implicitly convert type 'float' to 'byte'. An explicit conversion exists (are you missing a cast?)

means that you try to assign a value for a type to another where information could be lost (generally).

A byte can hold integer values from 0 to 255. Time.deltaTime is a float, and it can hold much more different values. The compiler cannot implicitly convert from float to byte because you would lose a lot of data, so it asks you to explicitly do the casting (i.e. "tell me you're sure you want to do this").

So to simply make the issue go away, you'd have to do something like.

redcurrent = redcurrent + redtarget * (byte)Time.deltaTime; 

However, in this case, that's not what you want. You want to change the type of redtarget and others to float, because you'll have to take the floating point values in consideration in this current situation, whereas you could not with byte.

Only doing this, you'll get more type conversion errors when trying to create a Color32 object.

To do that, you cast the values when/where you need them:

theobject.GetComponent<Renderer>().material.SetColor( "_EmissionColor", new Color32( (float)redcurrent, (float)greencurrent, (float)bluecurrent, opacitytarget)) ; 

The error

Cannot implicitly convert type 'float' to 'byte'. An explicit conversion exists (are you missing a cast?)

means that you try to assign a value for a type to another where information could be lost (generally).

A byte can hold integer values from 0 to 255. Time.deltaTime is a float, and it can hold much more different values. The compiler cannot implicitly convert from float to byte because you would lose a lot of data, so it asks you to explicitly do the casting (i.e. "tell me you're sure you want to do this").

So to simply make the issue go away, you'd have to explicitly convert the Time.deltaTime to byte like this:

redcurrent = redcurrent + redtarget * (byte)Time.deltaTime; 

However, in this case, that's not what you want. You want to change the type of redtarget and others to float, because you'll have to take the floating point values in consideration in this current situation, whereas you could not with byte.

Only doing this, you'll get more type conversion errors when trying to create a Color32 object.

To do that, you cast the values when/where you need them:

theobject.GetComponent<Renderer>().material.SetColor( "_EmissionColor", new Color32( (float)redcurrent, (float)greencurrent, (float)bluecurrent, opacitytarget)) ; 
Source Link
Vaillancourt
  • 16.4k
  • 17
  • 56
  • 61

The error

Cannot implicitly convert type 'float' to 'byte'. An explicit conversion exists (are you missing a cast?)

means that you try to assign a value for a type to another where information could be lost (generally).

A byte can hold integer values from 0 to 255. Time.deltaTime is a float, and it can hold much more different values. The compiler cannot implicitly convert from float to byte because you would lose a lot of data, so it asks you to explicitly do the casting (i.e. "tell me you're sure you want to do this").

So to simply make the issue go away, you'd have to do something like.

redcurrent = redcurrent + redtarget * (byte)Time.deltaTime; 

However, in this case, that's not what you want. You want to change the type of redtarget and others to float, because you'll have to take the floating point values in consideration in this current situation, whereas you could not with byte.

Only doing this, you'll get more type conversion errors when trying to create a Color32 object.

To do that, you cast the values when/where you need them:

theobject.GetComponent<Renderer>().material.SetColor( "_EmissionColor", new Color32( (float)redcurrent, (float)greencurrent, (float)bluecurrent, opacitytarget)) ;