- Home /
Using int to get specific variable from array does not work,Using int to get specific variable in array
Hello. This line of code does not work as intended:
artworkImage.sprite = defaultCard.artwork[defaultCard.selectedArtworkNumber];
defaultCard.selectedArtworkNumber does indeed change. I've used debug.log to find out that the changing of that variable does indeed work. It is that line that does not work. It works if i input eg. 0. defaultCard.selectedArtworkNumber is an integer so it should work according to my logic. There is no error in the console. ,Hello. This line of code does not work as intended:
artworkImage.sprite = defaultCard.artwork[defaultCard.selectedArtworkNumber];
defaultCard.selectedArtworkNumber does indeed change. I've used debug.log to find out that the changing of that variable does indeed work. It is that line that does not work. It works if i input eg. 0. defaultCard.selectedArtworkNumber is an integer so it should work according to my logic. There is no error in the console btw.
What do you mean by "does not work". There can be plenty wrong with this piece of code. The index can be out of range, element at that index may be null or it could be something you don't expect... You really need to elaborate here.
Set a breakpoint at that line and check if it even executes. And while you have the code stopped at that breakpoint, check what's inside the array and specifically at the index you want.
Also maybe something is overwriting the sprite, so you don't see this specific change?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Do you know the solution of this probelm? (Problem is in the details) 0 Answers
Code for picking item up isn't working.,Why isn't my pick up item code working? 2 Answers
How do I update the position of different prefabs to the current position? 0 Answers