Having a hard time changing a color to a color i have stored in an array. The line that throws the error is the one in my update.
(This is only a sample of code to make it easy to read)
public var playerColors:Array=Array();
public var currentColor:Color;
The error i am getting is this…
BCE0022: Cannot convert ‘Object’ to ‘UnityEngine.Color’.
which makes sense, but im not sure how to correct it.
I have tried using many methods, but still get this or other errors(based on the method used). Can someone please give me some insight as to what i am doing wrong and a solution. Thank you in advance.
Well, if you're not using any dynamic stuff, why not just use a builtin array and avoid that whole mess?
public var playerColors : Color;
That way, your indexing will work properly.
By the way, the reason for your problem is that #pragma strict removes all dynamic typing. The practical upshot of this is that you can't just get a value out of an Array class- you need to cast it back to the type that you need it to be.
currentColor = (Color)playerColors;
However, Unity's Array class is slow and badly typed, so you're better off just using the builtin one.
If you need the ability to dynamically add and remove objects (but the objects will only ever be of a single type), you might be better off using
var playerColors : System.Collections.Generic.List.<Color> = new System.Collections.Generic.List.<Color>();
This has Add and Remove methods, as well as some other things you might find useful. If that name is a bit too long for you, add a directive importing System.Collections.Generic at the top of your file.