Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

InvalidCastException with .net datatypes but not with UnityEngine.Object

$
0
0
The following returns the following error: Line 11: InvalidCastException: Cannot cast from source type to destination type. It works perfectly with anything that inherits from UnityEngine.Object. I don't understand how to prevent this from happening with .net datatypes.
void Start () {

        float[] f = new float[5];
        f[0] = 4.5f;
        Test(f);
	}

    void Test(object t)
    {
        if (t is Array)
        {
            Debug.Log("isarray");
            object[] a = (object[])t;
            if (a[0] is float)
            {
                Debug.Log("isfloat");
            }
        }
    }

                       

Viewing all articles
Browse latest Browse all 171066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>