|
Hi, What I am trying to do is, get the key pressed and pass it to a function which instantiates a prefab. (I have a prefab for each letter, so I'd rather not do a if/else structure with 30 clauses) here's what I have got:
now the "letter" variable is to be given by the user how? My search lead me into Events and other dark places :) I also hope that Instantiate() can take in chars or strings as a parameter, or all this would be in vain. Thanks in advance.
(comments are locked)
|
|
Yes I think you're on the right track looking into Events. Something like this might work:
Your 'spawn' method would then be sent a character in the 'letter' argument variable. However, then you need some way to tie your gameobject prefabs to the character code pressed. There are a number of ways to do this, none of them are particularly fun to implement. One method would be to put your prefabs into the Resources folder. This allows you to reference them directly by name. If you put them in the Resources folder, and call them "Letter_a" through to "Letter_z", you could use code like this to instantiate them:
Hope this helps! Hi Duck, Thanks for the great explonatoray response :) I get an error saying: "An instance of type 'UnityEngine.Event' is required to access non static member 'character'." The Resources info is amazing, thank you, even though I could not get it to work :)
Feb 18 '10 at 07:17 AM
sulas
Sorry, that should have been "Event.current.character" rather than "Event.character"
Feb 18 '10 at 03:15 PM
duck ♦♦
If you have more specific problems using "Resources", have a search of this site, or failing that, post a new question describing it in more detail!
Feb 18 '10 at 03:15 PM
duck ♦♦
(comments are locked)
|
