Unity Engine Dotween Usage And Details – 2023

    09.01.2023
    832
    Unity Engine Dotween Usage And Details – 2023

    In this lesson, I will introduce Dotween Unity, a popular plugin that you can use in your unity Dotween Pro apps. Using this plugin, you can change the current value of one variable to another value softly (within a specific time). To give a simple example, you can move an object from its current position to another position in 1.5 seconds.

    unity 3d dotween functions
    unity 3d dotween tutorial functions

    Unity 3D DOTween Download

    Let’s start then!
    After importing the plugin into your project, the first thing you need to do is follow the path of the Tools-Demigiant-DOTween Utility Panel and click on the “Setup DOTween Unity…” button in the incoming window. Then add the following line to the beginning of your C# script(s)that you intend to use the plugin: “using DG.Tweening;

    DOTween already comes with many functions, and I can’t process them all here, so I’ll only talk about functions that I find important. Click for original documentation: /documentation.phpunity 3d java or set active false unity!

    Unity 3D Popular Functions

    • transform.DOLocalMove(Vector3 targetLocalPosition, float time): It targets the localposition value of the Transform object (the Position value in the Inspector) within sure seconds. For example, to make localposition 0.0.0 in 1.5 seconds: transform.DOLocalMove( New Vector3( 0f, 0f, 0f ), 1.5 f );
    • transform.DOLocalMoveX(float targetXLocalPosition, float time): Changes the x value of the Transform object’s local position. There are also separate functions for the Y and Z axes.
    • transform.DOMove(Vector3 targetPosition, float time): Changes the position value of the Transform object. Similar to dolocalmove, this function also has versions of DOMoveX, DOMoveY, and DOMoveZ.
    • transform.DOLocalRotate(Vector3 targetLocalEulerAngles, float time): Changes the localeulerangles value of the Transform object (the Rotation value in the Inspector). For direct eulerAngles, there is a DORotate function.
    • transform.DOScale( Vector3 targetLocalScale, float time): Changes the localscale value of the Transform object (the Scale value in the Inspector). There are also separate versions for the X, Y, and Z axes only.
    • camera.DOShakePosition(float time, float power): It vibrates the position of the camera at power intensity for sure seconds (for example, it can be used when the bomb explodes in the game). To vibrate the rotation of the camera.Doshakerotation has a function. I recommend entering a small amount, such as 0.2 as the power when shaking the position, and a larger amount, such as 30.0, when shaking the rotation.
    • materyal.DOColor(Color targetColor, float time): Changes the colour of the material. Technically speaking, it changes the value of a variable named “_Color” in the material’s shader. If you want to change the value of another shader variable, you can use the DOColor(colortarget, string variable, float time) function.
    • material.DOFade(float targetAlpha, float time): Changes only the alpha value (transparency) of the colour of the material. As with docolor, there is a variant of this function that takes a variable.
    • uiElement.DOColor(Color targetColor, float time): Changes the colour of a UI element. Only the DOfade function can be used to change the alpha value of the colour.
    • DOTween.Kill(object targetObject, bool CompTween = false): it serves to manually terminate all tweens running on the target. If CompTween is true, the target values are applied to targetobje before the tweens are terminated.
    • DOTween.KillAll(bool completetween): Terminates all tweens that are running.

    Handmade Tween (DOTween)

    Sometimes there may not be a ready-made DOTween function that allows you to mollusk the desired value. In this case, you can use a special function: DOTween.To(getfunction, set function, target value, time)

    • Get function: here, you must enter a function that returns the current value of the variable that you want to reach in the target.
    • Set function: a function that allows you to assign this new value back to your variable, as the value of the variable taken from the current value by the get function softly approaches the target by the Dotween Position.
    • Target value: the last value that you want the variable to receive
    • time: smooth transition time

    For example, let’s say you have a float variable named variable in your script and you want to make it 5.0 in 2 seconds:

    DOTween.To( () => factor, (newValue) => factor = newValue, 5.0f, 2f );
    
    

    You might be confused if you haven’t seen the “() => blabla” pattern here before. This template is used to quickly create anonymous functions (you can search for “C# lambda” for more information). A long way to write the same code is:

    float Variable;
      
    void Start()
    {
        DOTween.To( GetTheValueOfTheVariable, ChangeTheValueOfTheVariable, 5.0f, 2f );
    }
      
    float GetTheValueOfTheVariable()
    {
        return Variable;
    }
      
    void ChangeTheValueOfTheVariable(float NewValue)
    {
        Variable = NewValue;
    }

    Another interesting thing you can do with this function is to make a string appear softly from nothing (an effect we see from time to time in games). For example, you want to draw on the screen with OnGUI “Hello World!” you can use the following code to make your message appear slowly in 5 seconds as if someone was writing that string manually at that moment:

    string AppearingText = "";
      
    void Start()
    {
        DOTween.To( () => AppearingText, (text) => AppearingText = text, "Hello World!", 5f ).SetOptions(true, ScrambleMode.None);
    }
      
    void OnGUI()
    {
        GUILayout.Box(AppearingText);
    }

    SetOptions function here, only DOTween.To valid when changing the value of a string with. If you set the value of ScrambleMode.None to ScrambleMode.Instead of appearing out of nowhere, a string with randomly mixed letters will slowly shift towards the target text.

    Note: DOTween.The types supported by the function are float, double, int, uint, long, long, Vector2, Vector3, Vector4, Quaternion, Rect, RectOffset, Color, and string.

    Extra Functions

    unity 3d extra functions
    unity 3d extra functions

    These functions, when added to the end of the above-mentioned functions, give these functions extra functionality.

    SetDelay(float time):

    Keeps the function running for a few seconds. For example, if you want to increase the local scale of the object by 2 times in 5 seconds, but want to wait 1 second First: transform.DOScale( transform.local scale * 2, 5f ).SetDelay( 1f );

    SetRelative(true):

    It adds a target value softly to the value of the variable rather than softly bringing the variable’s value to the target value. So, for example, if you want to move your object 5 units forward in 1.5 seconds, and even if you want to wait 1 second before this process, you can use the following code: transform.DOLocalMove( new Vector3( 0f, 0f, 5f ), 1.5f ).SetRelative( true ).SetDelay( 1f );

    From(bool relative):

    It moves the value of a variable from the current value to the current value rather than moving it from the current value to the target value. In other words, when this function is called, the value of the variable is instantly equal to the target value and moves smoothly from that value to its original value. If you want this operation to be “added above the value”, as in Setrelative, make the relative parameter of this function true instead of using the SetRelative function. If not, make it false.

    SetEase(Ease softMotionTour):

    Determines how soft the value of the variable moves to the target value. Ease by default.OutQuad is used, meaning that while the value of the variable changes at normal speed at first, it begins to change more slowly as it approaches the target value. Ease You. If you use Linear, the value of the variable always changes at a constant speed. To see all Ease values and how they work, visit the following page: https://easings.net/

    SetUpdate(UpdateType updateTour, bool timeScaleIndependent):

    Is the function in Update (UpdateType.Normal), in Late update (UpdateType.Late) or FixedUpdate (UpdateType.Fixed) determines that it will work. If you make the value of timeScaleIndependent true, the function Time. Not affected by timescale (ideal for UI animations that run when the game is paused).

    SetLoops(int loopQuantity, LoopType loopTour):

    Makes the function repeat itself (eg run twice). LoopQuantity determines how many times the function will be repeated, while loop tour determines how the repeat will occur. If LoopType.Restart is entered, the function is run from the beginning of LoopType.Yoyo is entered, the function is from end to end and then from beginning to end, etc. It is repeated as. LoopType.Incremental, the more the value of the variable has changed, the more it adds to the last value of the variable in subsequent iterations. If you set the loop mount to -1, the function will repeat itself forever. For example, if you want an object to move at a constant speed between its initial position and its 0,0,0 point (each movement lasts 2 seconds): transform.DOMove( new Vector3( 0f, 0f, 0f ), 2f ).SetLoops( -1, LoopType.Yoyo ).NetEase( Ease.Linear );

    SetTarget (Object targetObje):

    Determines the targetable as the owner of this tween. When DOTween.Kill (targetable) is done; this function terminates the run—all functions except DOTween.To automatically assign a target object, so you don’t need to call SetTarget in those functions.

    OnComplete (will work function):

    When the function is finished, it causes a certain function (Function to run) to run. If the function repeats itself (loop), the function to run is called only when all loops are completed. For example, if you want to Dotween Rotate an object 90 degrees around the Y-axis in 5 seconds and then destroy it, you can write a code like this: transform.DOLocalRotate( new Vector3( 0f, 90f, 0f ), 5f ).SetRelative( true ).OnComplete( () => Destroy( transform.gameObject ) );

    OnStepComplete (function that will work):

    Unlike OnComplete, if the function is looping, the Function that will run at the end of each loop is called (also called when all loops are completed).

    OnUpdate (will work Function):

    As long as the function runs, every frame will run. The function will be called.

    This is the end of this lesson here. I hope it was useful. Take care of yourselves!
    For more; Unity 3D

    AUTHOR INFO
    Welcome to Gameplay Developer, your number one source for all things related to 30 Rose Lane, Henderson, NC... We're dedicated to giving you the very best of 30 Rose Lane, Henderson, NC. with a focus on quality and real-world problem solutions.
    COMMENTS

    This site uses Akismet to reduce spam. Learn how your comment data is processed.