|
I've been on working on instantiating 10 boxes and giving them some properties. They all get the same properties for now but it i want to be able to give them different props in the future. The code worked until I put it in #pragma strict mode.. Now it says there is a Nullreferenceexeption when i ask for the obstakel. Any ideas on what could solve my problems are very welcome!
(comments are locked)
|
|
I would assume that obstaklePrefab is not of type GameObject. By the way, in Unity 3.4 you can just write this: Instantiate returns the type of the prefab being instantiated (instead of Object as before), and GetComponent returns the type of the component (instead of Component as before). Actually you can shorten it: Or even more: Thank you! That last line is perfect, it doesn't solve the problem, it eliminates it. I'm on a school macbook and updates will have to wait till school starts again but the last line works in 3.3 as well. [edit: no wait, it doesn't: getcomponent not a member of Unity.object] Moral of the story, work with up to date software.
Aug 09 '11 at 05:53 PM
YvdB
@YvdB: You can still do it in one line on 3.3 as long as you cast appropriately: That's maybe a bit much for one line of code though.
Aug 09 '11 at 06:38 PM
Eric5h5
(comments are locked)
|
