|
In script, I instantiate a NavMeshAgent. For some reason, it's impossible to cast the Object Instantiate creates to a GameObject, and therefore to do to get the NavMeshAgent properties. Here's my code: Anyone have any idea what I'm doing wrong? :/ I'm completely new to Unity and C#, so feel free to state the obvious!
(comments are locked)
|
|
Nope, all your casting advises are not the solution: does exactly the same. (As it should). However, I did find out what the problem was by now: the variable 'prefab' which was filled by dragging something there was declared as So it's not a GameObject but a Transform. Changing this declaration to solved the problem! +1 for posting your own solution. Now accept your answer (the round checkmark under the up/down vote icons on the left)
May 18 '12 at 01:56 PM
asafsitner
(comments are locked)
|
|
Try this line instead: This or
May 18 '12 at 11:06 AM
asafsitner
(comments are locked)
|

try GameObject instance = (GameObject) inst as GameObject or Instantiate(prefab, position , Quaternion.identity) as GameObject.