x


Scale GameObject to an Other GameObject

Hello everyone! I have 2 gameObject: an Enemy and a Plane. In Plane I want to show a Texture with a circle. The problem is: how I scale the plane to the Enemy's dimension? using scale make a wrong result..

Ps. I'm a newbie.. Thanks for all

more ▼

asked Apr 12 '12 at 11:14 AM

dukearena gravatar image

dukearena
59 2 6 11

you can use parent of game object.that time when you scale the parent, child automatically scale. file://localhost/Applications/Unity/Unity.app/Contents/Documentation/Documentation/ScriptReference/Transform-parent.html
You can try this.......

Apr 12 '12 at 11:21 AM subbuunity
Apr 12 '12 at 11:34 AM alucardj
(comments are locked)
10|3000 characters needed characters left

5 answers: sort voted first

This is my working code:

// I dont' need a Vector3 becouse plane size is (1,1,1) so the "perfect" size
// for this is (resValue, resValue, resValue) 
var resValue : float;
function Update(){
    var enemySize : Vector3 = enemy.renderer.bounds.size;
    // planeScaleAxis(1) : resValue = x : enemySizeAxis
    var planeX : float = enemySize.x / resValue;
    var planeY : float = enemySize.y / resValue;
    plane.scale = Vector3(planeX, 0, planeY);
}

Thanks for your answers captaincrunch80!!!

more ▼

answered Apr 13 '12 at 09:46 AM

dukearena gravatar image

dukearena
59 2 6 11

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

Best you leave enemy scale to 1,1,1 all the time.

Now get the dimensions of the enemy with it's bounding box.

Depending on what you are trying to do this could be Collider.bounds, Mesh.bounds, Renderer.bounds

With the bounding box dimensions you can scale your plane. Make sure the plane is 1 unitylong and one unit wide,so you do not have to do facy unit conversions. Now wosition the plane and scale scale the X and Z axis. Done!

more ▼

answered Apr 12 '12 at 03:37 PM

captaincrunch80 gravatar image

captaincrunch80
240 1 3 4

Dude, you right!!! Thanks a lot!

Apr 12 '12 at 05:32 PM dukearena
(comments are locked)
10|3000 characters needed characters left

Hi again!

As I said, you need to check the bounding box of the enemy! There you have the dimensions. With these you can scale the plane accordingly.

---------- /* C# */ // Get the enemy dimensions Vector3 enemyDimensions = enemy.renderer.bounds.size;

// Set the plane scale
myPlane.transform.scale 
       = new Vector3(enemyDimensions.x, 0.0f, enemyDimensions.y);

  • For this to work, the plane has to have the dimensions Vector3(1,0,1)
  • Make the plane a child of enemy and set it in relative space under the enenmy

I have not tested this (not much time) but it should work this way.

more ▼

answered Apr 12 '12 at 06:27 PM

captaincrunch80 gravatar image

captaincrunch80
240 1 3 4

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

The problem is that i don't know what is the value to assign... If I manually set the Plane scale to (1, 1, 1) and set the enemy scale to (1, 1, 1), they have different dimensions..

How I can find the "same dimension values"?

more ▼

answered Apr 12 '12 at 01:33 PM

dukearena gravatar image

dukearena
59 2 6 11

(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:

x2088
x388

asked: Apr 12 '12 at 11:14 AM

Seen: 1120 times

Last Updated: Apr 13 '12 at 09:46 AM