Hi all!
I’m trying to Scale up my Player when he walk into a BoxCollider. (On Trigger)
With this Script attached to the Box-Collider-Object, it scale up the Box-Collider - not the player:
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
// Widen the object by 0.1
transform.localScale += new Vector3(2f, 2f, 2f);
}
}
So I want to opposite to happen
When I Attached this line to my Player Script, its basically working.
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "ScaleUp")
{
// Widen the object by 0.1
transform.localScale += new Vector3(2f, 2f, 2f);
}
}
But I want to attach the Script to the BoxCollider-Object so I can change the scale from the Inspector instead.
Any idea how to make that work?
So, just transform.localScale is referencing to GameObject which has this script, if your have this script on box, Collider2D other is your player, so if you would like to scale player, get transform of other and scale it.