Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

C# Getting "Cannot cast from source type to destination type" even though it's working.

$
0
0
Relevant part of the script: public object[] pictures; public int counter = 1; void Update (){ GetComponent().sprite = (Sprite)pictures[counter]; } This code works as it should, it changes the sprite of my GameObject to the desired object in the pictures[] array, the script works fine. But my only problem is that every frame the compiler gives me the **"Cannot cast from source type to destination type"** error, even though it works as it should. I would ignore this, but I'm pretty sure that when I try to build the game it wouldn't let me until I fix this error. What is wrong, and how do I fix it?

Viewing all articles
Browse latest Browse all 7934

Trending Articles



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