Shrinking an object on trigger

Hello I am trying to shrink an object on trigger, I have been working with this code.

public Transform redu;

void OnTriggerEnter (Collider trig)
{
if (trig.gameObject.tag == “PickUp”)
redu.transform.localScale (0, 0, 1);

}

I have gotten the same object to rotate on trigger but I can’t seem to get it to change size. Any help would be great thanks.

localScale isn’t a function… it’s a property. Have a look at the scripting reference for it: Unity - Scripting API: Transform.localScale

Ok thanks, I doesn’t suppose you can give me a script example to achieve what I want. To change the size/scale of an object on trigger or on a time scale.

This will shrink an object 90% its size on the x and y scale OnMouseDown on the object you are shrinking. Youll have to modify to work with OnTrigger instead, but should do the job i think :slight_smile:

Vector3 defaultScale;

	void OnMouseDown()
	{
		defaultScale = transform.localScale;
		Vector3 scale = defaultScale;
		scale.x = scale.x *0.9f;
		scale.y = scale.y * 0.9f;
		transform.localScale = scale;
}

Hi thanks that works, I modified it to work on trigger however I would like it to shrink each time it hits the trigger, any help would be grateful thanks.

is there any particular reason why you would want to do that via scripting?

if not, simply use inbuilt animation component. Just record whatever you want to do to the object and trigger it.

assuming your animation is triggered by shrink boolean.

myObject.animation("shrink", true);

To be honest I didn’t know about the animation component lol

thanks I will have a mess with it