Question by
jackgoodall14 · Nov 08, 2021 at 11:42 AM ·
functions
How can i reverse a function by doing the same action again?,How do I revert a transformation after previously transforming it?
So, i'm very new to coding in c#, and i'm mainly just testing things out. At the moment, I have an option to where whenever you click on the square, it shrinks by a factor of 2 and changes colour. I would like to implement this for different puzzles and would like to revert the changes back to its original transformation if I click it again. Here's the function:
private void OnMouseDown()
{
//shrinks the square by a factor of 2
tr = GetComponent<Transform>();
transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
//changes colour to blue
rend = GetComponent<SpriteRenderer>();
rend.color = Color.blue;
//changes hitbox to a suitable hitbox for the square
hb = GetComponent<BoxCollider2D>();
hb.size = new Vector2(1f, 0.94f);
}
Pretty much I thought this would be useful for climbing through smaller areas and then it would be necessary to go back to normal in some other areas. any help is appreciated thanks.
Comment