Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by .hooligan · Feb 02, 2011 at 03:20 AM · itween

iTween oncomplete not firing

Hey guys, quick question. I have the following method that fires a camera shake using iTween. I set the oncomplete property to a method inside the same class but it doesn't seem to be firing. Here is what I have. I'm sure I'm missing something but I can't seem to see what.

public void CameraShake(float magnitude, float duration) {

     cameraShaking = true;

     Hashtable ht = new Hashtable();
     ht.Add("x", magnitude);
     ht.Add("y", magnitude);
     ht.Add("time", duration);
     ht.Add("oncomplete", "onCameraShakeComplete");

     iTween.ShakePosition(mainCamera.gameObject, ht);

 }

 public void onCameraShakeComplete()
 {
     cameraShaking = false;
     print("Done");
 }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
21
Best Answer

Answer by pixelplacement · Feb 04, 2011 at 05:07 PM

If I had $1 for every time this has been asked!

By default iTween attempts to call the callback methods you provide it on the object it is animating - in your case the mainCamera.gameObject. Since "onCameraShakeComplete" does not reside on that object it is never getting called. You have two options: Move that method onto your mainCamera.gameObject or simply provide am "onCompleteTarget" of gameObject to tell iTween to use the GameObject that is setting up this iTween.

Hope that helps.... I hate typing this answer up ;)

Good luck!

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image .hooligan · Feb 05, 2011 at 11:18 PM 0
Share

Really sorry, but thanks for the reply. I appreciate it.

avatar image qholmes · Apr 19, 2011 at 08:10 PM 0
Share

I am sure people ask this a lot!!! but i can not make it work with the visual editor. I put my iTween name in the oncomplete spot and then drag the object that contains the iTween into the target spot and nothing happens.... Even if both iTweens are on the same object it still does not work

avatar image pixelplacement · Apr 20, 2011 at 02:19 AM 0
Share

http://pixelplacement.com/2011/02/21/understanding-itween-callbacks/

avatar image qholmes · Apr 20, 2011 at 05:15 AM 0
Share

Ok now i can get an iTween to run with the OnComplete if it is on the same object by not specifying an object at all... i was dragging the object onto the variable even if it was the same one... But i still cant get it to work if the iTween is on a different object even if i drag out the target object variable.. And why does the iTween start right away when it is specified with the OnComplete function? That messed me up as well. I thought it was not working until i put a few second delay on the second iTween then i realized it was just firing right away ins$$anonymous$$d of after the first one was done

avatar image qholmes · Apr 20, 2011 at 07:16 AM 0
Share

Ok i take it back the running a second iTween from OnComplete that is on the same object is not working the reason it was firing right away was because i was calling it from my other script. So my question still is why cant i get the OnComplete to work from the visual editor?

Show more comments
avatar image
1

Answer by humam · Sep 19, 2014 at 02:06 PM

even after adding "oncompletetarget" , mainDraggablePannel.gameObject i couldnt achieve the result.... since my i had a seperate script object.... for that i changed it to "oncompletetarget",this.gameObject and it worked!!

 >     public void onBackButtonPressed(){
 > 
 >         iTween.MoveTo
 > (mainDraggablePanel.gameObject,
 > iTween.Hash
 > ("x",0.0f/*mainDraggablePanel.transform.localPosition.x-UICamera.lastHit.collider.transform.localPosition.x*/,
 >                                                                    "y",0.0f,
 >                                                                    "time", 1.5f,
 >                                                                    "easetype",
 > iTween.EaseType.easeOutQuad ,
 > "oncomplete" , "ScaleDownOnZoomOut" ,
 > "oncompletetarget" , this.gameObject
 > /*iTween.EaseType.easeInOutElastic*/));
 > 
 > 
 >         backButton.SetActive (false);     }
 > 
 >     public void ScaleDownOnZoomOut(){
 >         Debug.Log("yolo");
          iTween.ScaleTo
 > (mainDraggablePanel.gameObject,
 > Vector3.one, 2.5f);
 > 
 > 
 >     }

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kurius · Jan 22, 2016 at 02:03 AM 0
Share

Thank you! That solved it for me!... "oncompletetarget",this.gameObject

avatar image
1

Answer by umair_hassan · Apr 15, 2015 at 12:43 PM

Refer a gameobject on which current script is attached in your code.

 iTween.ScaleBy(enemy[value], iTween.Hash("x", 0.5,"y",0.5, "delay", .1,"oncomplete", "kill","oncompletetarget",gm));

here gm is a gameobject on which your script is attached. :)

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tkamruzzaman · Nov 21, 2015 at 05:42 AM 0
Share

here gm is a gameobject on which your script is attached. :)

Thank You @umair_hassan :)

avatar image umair_hassan tkamruzzaman · Nov 21, 2015 at 05:45 AM 0
Share

no problem man ;)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

iTween a few questions 0 Answers

Collision Detection does not work in my scene 1 Answer

iTween how to define what object will be tweened 1 Answer

Camera shaking and parent movement 1 Answer

C# - create an iTweenPath in the Sourcecode 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges