-1
\$\begingroup\$

How to change the scale values of object by using Lerp. from 0 to 0.01722f and reveals later ?

public Vector3 vp1;
public bool checkers;

void Start()
{
    checkers = false;
    vp1 = gameObject.transform.localScale; // (0.01722F,0.01722F,0.01722F)
}

void Update()
{

    if (checkers == true)
    {
            vp1 = Vector3.Lerp(new Vector3(0, 0, 0), vp1, 0.2f);
    }
     else
    {
            vp1 = Vector3.Lerp(vp1, new Vector3(0, 0, 0), 0.2f);
    }

}
\$\endgroup\$
6
  • 1
    \$\begingroup\$ Vector3 are a struct, they are passed by value and not reference. you need to pass it back to the gameObject transform with: transform.localScale = vp1; at the end of your update. \$\endgroup\$ Commented Dec 24, 2019 at 13:09
  • \$\begingroup\$ Sorry I did not understand you. Could you script it please. \$\endgroup\$ Commented Dec 24, 2019 at 13:26
  • \$\begingroup\$ @OmarGuendeli post that as an answer so it can be accepted and upvoted. :) \$\endgroup\$ Commented Dec 24, 2019 at 14:16
  • \$\begingroup\$ Yes, Now I can understand what he meant. anyway. Still the lerp not doing his job !! There is no smooth or good transfer of scale values !! here is the new script. It's from the lerp or from me ? \$\endgroup\$ Commented Dec 24, 2019 at 15:28
  • \$\begingroup\$ Please edit your question to include what you changed, and describe what behavior you're seeing, and how it differs from what you want. \$\endgroup\$ Commented Dec 24, 2019 at 18:58

1 Answer 1

0
\$\begingroup\$

Anyway. Here how to solve the scale lerp.

public Vector3 vp1,vp2,vp3;
public bool checkers;

void Start()
{
  checkers = false;
  vp2 = new Vector3(0.0f, 0.0f, 0.0f);
  vp3 = new Vector3(0.001722403f, 0.001722403f, 0.001722403f);
}

void Update()
{

    gameObject.transform.localScale = vp1;

  if (checkers == true)
  {
      vp1 = Vector3.Lerp(vp1, vp3, Time.deltaTime * 8f);
  }
   else
  {
      vp1 = Vector3.Lerp(vp1, vp2, Time.deltaTime * 20f);
  }

}
\$\endgroup\$
1
  • 1
    \$\begingroup\$ This answer would be better if it explained what you had to change and why that solves the problem. \$\endgroup\$ Commented Dec 24, 2019 at 20:27

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.