- Home /
How to make box collider same size as gameobject
I am creating a gameobject from from an .obj exported from blender and now I want to add a box collider to this object in order to be able to click on it but I am having trouble making it the same size. Currently I am using the gameobjects scale to set the size but this does not seem to be the right way of doing things as it makes my boxcollider a cube. This is the code I currently have to create my gameobject and collider where humanPriest is a reference to my object that I imported from blender.
Card card = new Card(0);
card.cardObject = (GameObject) GameObject.Instantiate(humanPriest,new Vector3(Camera.current.transform.position.x,Camera.current.transform.position.y-25.0f,Camera.current.transform.position.z+10.0f),Quaternion.Euler(new Vector3(5.0f, 0.0f, 0.0f)));
card.boxCollider = (BoxCollider) card.cardObject.AddComponent<BoxCollider>();
Then I try to change the size of the boxcollider like so.
foreach (Card c in userDeck) {
c.cardObject.GetComponent<BoxCollider>().size = c.cardObject.transform.localScale;
}
How can I get the actual size of my gameobject and set the boxcollider to the same size?
So I went to my imported .obj and checked "Generate colliders" and that may have solved my issue
Hey @markustenghamn I am trying to do the same thing, have you worked it out?
Your answer
Follow this Question
Related Questions
collisions in character not working! 2 Answers
shrinking objects 1 Answer
Mirroring a game object with children without messing up box colliders 2 Answers
How to create an 3d game object in 300 X 250 size? 1 Answer
UI Button Sizing unit 0 Answers