I've been trying to use iTween with C# and there always has casting problem..
How can I use iTween.MoveTo() FUnction in C#... iTween is written in C# but there is no example for iTween usage in C#.. What a shame with this?
Note : buttons *is the array of GUITexture..
*
*```*
*public void CreateMainMenu()*
*{*
*float startPosX = 0.0f;*
*float finalPosX = 0.5f;*
*float startPosY = 0.5f;*
*float offsetY = 0.1f;*
*buttons = new GUITexture[numButtons];*
*for (int i = 0; i < numButtons; i++)*
*{*
_buttons *= Instantiate(GUIButton, new Vector3(0.0f, startPosY, 1.0f), Quaternion.identity) as GUITexture;*_
_*//Animate the Button*_
_*Vector3 finalPos = new Vector3(finalPosX, startPosY, 1.0f);*_
_iTween.MoveTo((GameObject)buttons *, finalPos, 1.0f);*__*startPosY -= offsetY;*__*}*__*}*__*```*__*
The error for the above code is " Cannot convert GUITexture to UnityEngine.GameObject" .. How can I use iTween in C#??*__*anyone helps me...*__*please
only works on GameObjects, you can't use it on GUITexture. But there's good news: Each GUITexture also has a gameObject (because it's a component attached to a game object). You can access the GameObject of GUITexture via the gameObject property.
So, the solution is simply:
iTween.MoveTo(buttons*.gameObject, ...);*
*```*
*<p>... and ... as mentioned in my comment to your question: This has nothing do with C#.</p>*
GameObject button = buttons *as GameObject;*
*if( button != null)*
*iTween.MoveTo(button, finalPos, 1.0f);*
*else*
*Debug.Log("Button was null");*
*```*
*<p>EDIT:</p>*
*<p>Upon further investigation, a GUITexture does not inherit from GameObject. Therefore, a GUITexture is not a GameObject, and will return null if you try to cast it as one.</p>*