x


limit transform class localScale

hi

i built in a zoom function to make an object bigger or smaller using this code

 if (GUI.RepeatButton(pos6, "zoom out")) // make object smaller
    {
    transform.localScale.x -= 0.0007;
    transform.localScale.y -= 0.0007;
    transform.localScale.z -= 0.0007;

 if (GUI.RepeatButton(pos5, "zoom in"))
  {
    transform.localScale.x += 0.0007; // make object bigger
    transform.localScale.y += 0.0007;
    transform.localScale.z += 0.0007; 
  }

Question:

is there a code to limit the the transform.?

greetz,

more ▼

asked May 28 '10 at 08:54 AM

ab_cee gravatar image

ab_cee
35 10 10 14

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You would have to do it manually.

// C#

float Max = 1;
float Min = 0;

void Update()
{
     transform.localScale = new Vector3(
          Mathf.Clamp(transform.localScale.x, Min, Max),
          Mathf.Clamp(transform.localScale.y, Min, Max),
          Mathf.Clamp(transform.localScale.z, Min, Max)
     );
}

Something like that should do the trick.

more ▼

answered May 28 '10 at 09:39 AM

qJake gravatar image

qJake
11.6k 43 78 161

im so bad @ c#. Could someone make this in javascript?

May 28 '10 at 07:01 PM ab_cee

It's like, literally almost the same syntax. How can you not simply understand what's going on and then rewrite it? - Inside of Update(), set the local scale to itself, but clamp each of the values to a minimum and maximum value.

May 28 '10 at 09:52 PM qJake
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3462
x2091

asked: May 28 '10 at 08:54 AM

Seen: 1697 times

Last Updated: May 28 '10 at 08:54 AM