x


Help with resize script

I want to recreate this:
http://www.emanueleferonato.com/2011/10/25/develop-a-flash-game-like-cirplosion-as3-version-2/

But i cant limit my resize max and min. Why?



var velicina = 10;
var minvelicina = 8;
var maxvelicina = 60;




function Update() {

if(velicina >= maxvelicina)
{

velicina=maxvelicina;


}


if(Input.GetMouseButton(0))
{

transform.localScale += Vector3(velicina,0,velicina)* Time.deltaTime;


}


}
more ▼

asked Jan 13 '12 at 06:11 PM

GIOWorks_old1 gravatar image

GIOWorks_old1
1 1 2 3

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

1 answer: sort voted first

Because you are increasing the value of scale, not the value of velicina.

You may want to do this:

var velicina = 10;
var minvelicina = 8;
var maxvelicina = 60;

function Update() {
    if(velicina >= maxvelicina)
    {
        velicina = maxvelicina;
    }   

    if( Input.GetMouseButton(0 ))
    {    
        velicina += Time.deltaTime;
        transform.localScale = Vector3(velicina,0,velicina);
    }
}
more ▼

answered Jan 13 '12 at 10:44 PM

Kryptos gravatar image

Kryptos
7.2k 5 32

But spere doesnt scale up when i click mouse button?

Jan 13 '12 at 11:04 PM GIOWorks_old1

Can i write something like if(transform.localScale >= maxvelicina) transform.localScale = maxvelicina ?

Jan 13 '12 at 11:10 PM GIOWorks_old1

well in my solution, the scale might be too big. Try with smaller values.

Jan 13 '12 at 11:26 PM Kryptos
var velicina : float = 1.0;
var minvelicina : float = 0.8;
var maxvelicina : float = 6.0;

function Update() {
    if (Input.GetMouseButton(0))
    {    
        velicina += Time.deltaTime;
    }

    if (Input.GetMouseButton(1))
    {    
        velicina -= Time.deltaTime;
    }
    velicina = Mathf.Clamp(velicina, minvelicina, maxvelicina);
    transform.localScale = Vector3(velicina, 0, velicina);
}
Jan 13 '12 at 11:31 PM Kryptos

Thanks it works!

Jan 13 '12 at 11:56 PM GIOWorks_old1
(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:

x986
x790
x90
x68
x49

asked: Jan 13 '12 at 06:11 PM

Seen: 729 times

Last Updated: Jan 13 '12 at 11:56 PM