|
I'm trying to figure out how I can get this function to work as I often need to use it and using copy/paste all the time is getting messy. But I keep getting an error saying The variable infoSymbol of 'bookManager' has not been assigned. From this line:
(comments are locked)
|
|
Unless you assign a GameObject to infoSymbol at any point in your script (as I see you do in the commented out line just above) you will always get a null reference exception here. Try adding at the end of your MakeInfoSymbol() function. Better yet, have MakeInfoSymbol() return a GameObject, and then assign infoSymbol to it in your DoesPageNeedInfoSymbol function, like so: you also may want to make the symbol prefab be a public GameObject var at the top of your script so that it can be assigned in the editor, and then instantiated without using awkward string-literal resource loading. Thanks syclamoth, I dont want to add infoSymbol = symbolGameObjectName; directly so I can use other names like infoSymbolTwo etc.. I'm interested in your last approach with returning a game object. What would I do at that point in DoesPageNeedInfoSymbol() ?
Sep 14 '11 at 10:13 AM
apple741 1
In DoesPageNeedInfoSymbol(), you would have a line which goes something like Instead of using Resources.Load(whatever), you should consider putting a prefab at the top of your script, and instantiating that.
Sep 14 '11 at 10:21 AM
syclamoth
I seem to still get the infoSymbol no unassigned error even with this method? I'm was hoping to stick with resources.load so I can control the amount of memory used as this if for ios. Thanks again :-)
Sep 14 '11 at 10:36 AM
apple741 1
I can't say this often enough- but to quote Donald Knuth, "premature optimisation is the root of all evil". There's no need to make things too complicated for yourself before you even get it working, and in the end it probably won't make that huge of a difference unless you are dealing with a seriously huge amount of data. By the sounds of things, the Resources.Load bit isn't returning an object properly, and as such the object never gets instantiated- Look at all your error messages, and try doing it in a different way to see if it works better.
Sep 14 '11 at 10:41 AM
syclamoth
As far as I can tell, there is no real reason to use resources.Load for iOS devices, especially if the resource in question is a prefab, as opposed to say a texture or 3d model. When the project gets built, it only includes things which are being used in the project, and assigning objects in the inspector is one of the ways in which it does this.
Sep 14 '11 at 10:44 AM
syclamoth
(comments are locked)
|
|
Select the object you have attached this script onto, then in the inspector you can select the info-object needed for the script. You can also find gameobjects by code, with GameObject.Find("{name of it}"); If you need to spawn it, you can just make a variable like: var go:GameObject = new GameObject();
(comments are locked)
|
