|
I'm trying to access the MeshRenderer component from a Custom Editor, but I can't seem to figure out the syntax in C#. In JS what I'm trying to accomplish: In C#, this is what I've got: However, Unity tells me that I can't cast target as a GameObject.
(comments are locked)
|
|
This did the trick for me:
(comments are locked)
|
|
Have you tried using the 'as' keyword instead? Like changing "(GameObject)target" to "target as GameObject"? Another thing you can try is casting it to a transform first: hope it helps, Yoerick While this didn't solve my issue, I did learn about the differences between prefix casting and fast casting: http://gen5.info/q/2008/06/13/prefix-casting-versus-as-casting-in-c/
Nov 03 '11 at 09:23 PM
karl_
(comments are locked)
|

The issue is that "target" is not the game object itself, it's the component attached to the game object that your custom editor edits. Which is why casting to (scriptName) works.