|
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
(comments are locked)
|
|
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!!!
(comments are locked)
|
|
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! Dude, you right!!! Thanks a lot!
Apr 12 '12 at 05:32 PM
dukearena
(comments are locked)
|
|
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;
I have not tested this (not much time) but it should work this way.
(comments are locked)
|
|
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"?
(comments are locked)
|

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.......
possibly -> transform.localScale = [other].localScale;
http://unity3d.com/support/documentation/ScriptReference/Transform-localScale.html