0
\$\begingroup\$

I want to the obstacle Scale-In and Scale-Out using Dotween PlugIn? means some effect??

See this link: https://www.youtube.com/watch?v=_Tq4t0gx49g&t=569s

Image:

enter image description here

I want to give a effect on the obstacle?

script:

Obstacle.cs

void Update()
{
        goTopToDown();
}

void goTopToDown()
{

  foreach (Transform item in GetComponentsInChildren<Transform>()) 
  {
      if (item.tag == "obstacleobject") //some obtsacle slow
      {
          item.localPosition += Vector3.down * speed * Time.deltaTime;                   //move top to down object
      }
      if (item.tag == "movefastobject") //some obstacle fast
      {
           item.localPosition += Vector3.down * movefastobjectspeed * Time.deltaTime;     //move fast object
       }
  }
```
\$\endgroup\$
  • \$\begingroup\$ more information is needed for this question to be answered. What effect do you want to be achieved? \$\endgroup\$ – Millard Sep 15 at 16:27
  • \$\begingroup\$ @Millard I want to scale in and scale out on obstacles. see this link:youtube.com/watch?v=_Tq4t0gx49g&t=569s using dotween plugin?? \$\endgroup\$ – Rahul Patil Sep 15 at 16:52
0
\$\begingroup\$

Its quit simple, Here the code which will do the job:

    public void ScaleINOutAnimation(Transform objectTransform, float scaleIn, float scaleOut, float duration)
    {
        objectTransform.DOScale(scaleIn, duration).OnComplete(() =>
        {
            Debug.Log("Scale In done.");
            objectTransform.DOScale(scaleOut, duration).OnComplete(() =>
            {
                ScaleINOutAnimation(objectTransform, scaleIn, scaleOut, duration);
            });
        });
    }

As in the function parameter I used "Transform" to scale in and out Object if you are using "RectTransform" then just convert "Transform" to "RectTransform" and it will do the job.

How to use this function:

  • objectTransform: The object you want to animate.
  • scaleIn: The object scale you want for scale in.
  • scaleOut: The object scale you want for scale Out.
  • duration: Duration for "Scale In" animation or Duration for "Scale Out".

so the call will some thing like this:

ScaleINOutAnimation(this.GetComponent<Transform>(), 0.9f, 10.0f, 0.1f);

or

ScaleINOutAnimation(object, 0.9f, 10.0f, 0.1f);

I hope this help, Let me know if you need any help with this.

\$\endgroup\$
  • \$\begingroup\$ how to set your script in my script I edited my question? help \$\endgroup\$ – Rahul Patil Sep 16 at 5:42
  • \$\begingroup\$ Well just copy the function I've posted in the answer and past it to "Obstacle.cs" and then call the animation function from Start() function if you don't have Start function then create one. To call the function from start just past this "ScaleINOutAnimation(this.GetComponent<Transform>(), 0.9f, 10.0f, 0.1f);" in the Start function. and that it. Also make sure to add this to very first line of the script "using DG.Tweening;". \$\endgroup\$ – Swati Sep 16 at 6:11
  • \$\begingroup\$ thanks for the answer. I m first time working with Dotween PlugIn. \$\endgroup\$ – Rahul Patil Sep 16 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.