1
\$\begingroup\$

I have set the iTween path and also I have added a button. When I click on the button the object should start moving along the iTween path.But issue I'm facing is when I run my project at initial stage itself the object is moving on the iTween path which I have set not on the button click. Then I tried out placing the same code for moving upon button click and it'S still not working. Can anybody help me solve this issue and provide me with a piece of code for it. The code is here

void Start () { //iTween.MoveTo(gameObject,iTween.Hash ("path",iTweenPath.GetPath("BoxOut"),"time",5)); iTween.MoveTo(gameObject,iTween.Hash ("path",iTweenPath.GetPath("Pass"),"time",50)); } // Update is called once per frame void Update () { } 

The above code worked initially, when the project started running, the object starts moving on the path. Then I edited the code and added the code on button click and it's not working anymore. The edited code is below.

void Start () { //iTween.MoveTo(gameObject,iTween.Hash ("path",iTweenPath.GetPath("BoxOut"),"time",5)); iTween.MoveTo(gameObject,iTween.Hash ("path",iTweenPath.GetPath("Pass"),"time",50)); } // Update is called once per frame void Update () { } void OnGUI() { if(GUI.Button(new Rect(100,100,100,100),"gggggg")) { Debug.Log("fffffffffffffffffffffff"); resp=true; } } 

Its not working. Please help me out with a piece of code.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

You might want to try the new Unity 5 Gui, the OnGUI method is pretty outdated. Hope this code block is just for testing purpose. The function GUI.Button() draws the button on screen and also returns whether that button was pressed (a boolean). So whatever code you need to execute must be written inside the if block. Hope this solves the issue.

 void Start () { } // Update is called once per frame void Update () { } void OnGUI() { if(GUI.Button(new Rect(100,100,100,100),"gggggg")) { Debug.Log("Button Clicked"); iTween.MoveTo(gameObject,iTween.Hash ("path",iTweenPath.GetPath("Pass"),"time",50)); } } 
\$\endgroup\$
0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.