|
In my Inventory script (with #pragma strict turned on) I Get the error Cannot convert 'Object' to 'UnityEngine.GameObject'. var items : List.; function OnGUI () { for (var item : GameObject in items) { //error here I have gone everywhere but no one seems to have encountered this.
(comments are locked)
|
|
The correct and simple answer is this: I decided to come back to this after a while. And it took me an hour and a half but this is what works. Jessy and Eric5h5, thank you both so much for helping me to get the correct answer.
(comments are locked)
|
|
http://unity3d.com/support/documentation/ScriptReference/GameObject.GetComponent.html http://unity3d.com/support/documentation/Manual/Generic%20Functions.html which is a shorthand for There is tons of information on this on Unity Answers and the forum. I have no idea what you just said! :-\
Feb 23 '12 at 01:05 PM
Jessy
I already fixed the item.GetComponent problem I was having, with: i.SendMessage ("DragAndDrop"); But I still can't figure out the for loop error.
Feb 23 '12 at 01:13 PM
MithosAnnar
I never saw anything about SendMessage (which I do not recommend using).
Feb 23 '12 at 02:28 PM
Jessy
In Unityscript you should use
Feb 23 '12 at 04:39 PM
Eric5h5
Eric, you ought to make that an answer; you know UnityScript better than anybody, I think.
Feb 23 '12 at 06:12 PM
Jessy
(comments are locked)
|

The code you posted will compile and run without any errors. The reason no one has encountered any problem with this is because there isn't any. I would guess you actually have different code that's creating a problem.
I'll update the question now, with a more helpful list of problematic and complicated code =D
You need to listen to the errors you get; your code generates plenty of errors that aren't the one you gave us:
Take out the parentheses after var items : List.
items.Add(LOWERCASE I HERE)
Most importantly, you didn't define DropAndDrag.
After those things are taken care of, there are no longer any errors. This code is useless to us, and so doesn't help you get your question answered. You need to spend some time learning how to cut down on what is irrelevant, so you can move forward.
Please try to understand what you are saying. You post us snippets that don't compile, and don't yield the error you mentioned. That is useless.
when I did what you guys said to do with the for loop, it didn't work. And then I got the error for sending a message. My question was not at all, put across well and for that I am sorry.