Im using a very simple script to make an object get smaller over time
#pragma strict
function Update()
{
transform.localScale -= Vector3(0.002,0.002,0.002); // Reduce object size by .002 per frame
}
Now think of it like iron ore being mined, eventually the object will reach scale 0 once its all been mined. It’s at this point I want the reduce scaling to stop. (at the moment it goes into negative figures and grows again)
How can I set the object(objects scale) a value or percentage? I don’t want it to reach less than zero, better still be able to stop it at about 2% of the original size.
Do I have to assine an INT/Float value to each of the vector3 x,y,z co-ordinates (and if so… how?)
Or is there a more efficient way to do this?
The script so far now is-
#pragma strict
var beingMined : boolean = false;
function Update()
{
if(beingMined == true)
{
transform.localScale -= Vector3(0.002,0.002,0.002); // Reduce object size by .002 per frame
}
}
As usual any help/suggestions is greatly appreciated.
One possible way is to do this:
#pragma strict
var beingMined : boolean = false;
function Update()
{
if(beingMined == true)
{
// Check if the local scale of the object is greater than zero on all axes. And if yes, then only decrement
if(transform.localScale.x > 0 && transform.localScale.y > 0 && transform.localScale.z > 0 )
{
transform.localScale -= Vector3(0.002,0.002,0.002); // Reduce object size by .002 per frame
}
// This check makes sure that the scale does not reach below zero
if(transform.localScale.x < 0 && transform.localScale.y < 0 && transform.localScale.z < 0 )
{
transform.localScale = Vector3.zero;
}
}
}