Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I've made a prefab consisting of a Cube which I've first scaled to more resemble a brick. There's also a Rigidbody added to the cube (in the prefab). Now I want to use that prefab in a c# script to make a wall out of multiple bricks.

My question is, how can I access the dimensions of my brick (width, height, the z dimension size) so that in my script I can make bricks which are placed one next to the other (and then one on top of the other)?

I've looked at the documentation for GameObject and Rigidbody but I can't find anything helpful.

Just for refference, my script so far is:

public GameObject brick;

void Start () {
        Instantiate(this.brick, new Vector3(0.01326297f, -30.07855f, 100f), Quaternion.identity);
        // int brickWidth = this.brick.????;

    }
share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

Have you tried using bounds ?

I guess you can achieve what you're looking for using :

float brickWidth = brick.renderer.bounds.size.x;
share|improve this answer
    
Thanks, that works. I just must make the brickWidth variable into a float. –  Shivan Dragon Sep 6 '12 at 20:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.