David Abaev
David Abaev

Reputation: 696

Animation with dynamic parameter - Unity3d

I have an object - just cylinder (looks like chip) and I want to add to this object like Flip animation. When chip is flip - chip will go up and rotate in the air. Now I want to give a dynamic parameter determines Height for go up.

So right now I know 2 ways:

1) Is just in c# code write object.Rotate() with parameters

2) Write animation clip - and call in C# for Play - but here -I can't pass parameters (right or not?)

So please guys - just give me direction (links) for good Get started with unity3d. Sorry for my English - it's very bad I know ((

Upvotes: 1

Views: 2429

Answers (2)

user5242208
user5242208

Reputation:

You can pass parameters to Animation - because animation is just file(it's not a code). So sure - if you want to pass dynamic parameters - you have only one options - by scripts. Just write 1 method who take GameObject and parameters for rotation and its done! good luck

Upvotes: 0

Neven Ignjic
Neven Ignjic

Reputation: 679

The best way to do it purely by script is definitely by using tweeners, I would suggest using this tool : https://www.assetstore.unity3d.com/en/#!/content/27676

Now after downloading this asset to your Unity just create a new script and include the asset

using DG.Tweening;

And here is simple method for doing the actual jump with dynamic parameters.

public Transform chip;

void JumpWithRotation(float heightOfJump, float timeForJump){
    DOTween.Init(false, true, LogBehaviour.ErrorsOnly);
    chip.DORotate (new Vector3 (0, 180f, 0), timeForJump).SetEase (Ease.InOutSine);
    chip.DOMove (new Vector3 (0, heightOfJump, 0), timeForJump).SetEase (Ease.InOutSine);
}

The best thing about tweeners is that you can easily implement easing methods (making transition between two values (linear, sine, exponentional...)).

Upvotes: 1

Related Questions