- Home /
Question by
codenamed52 · Apr 18, 2019 at 08:09 AM ·
scripting beginnercomponentprimitives
BoundBox not working after being attached to GameObject using script
I'm trying to use BoundBox component for my project.
When I attach BoundBox using inspector it works fine.
But when I try to attach it to a generated cube, using script, the cube gets created and shows the BoundBox component under inspector but doesn't actually work.
void CreateBox(int x, int y) {
GameObject box = GameObject.CreatePrimitive(PrimitiveType.Cube);
box.transform.parent = PlayArea.transform;
box.transform.position = GetPositionByIndices(x, y);
box.transform.localScale = new Vector3(50f, 50f, 50f);
box.layer = box.transform.parent.gameObject.layer;
box.GetComponent<Renderer>().enabled = false;
box.AddComponent<BoundBox>();
}
What could be wrong?
Comment
Your answer
Follow this Question
Related Questions
How to apply script saved in variable 2 Answers
2D Animation does not start 1 Answer
Enabling multiple Monobehaviour Components in a game object 1 Answer
Problem with spawning with companion AI,Script not working properly when GameObject reactivated? 0 Answers
Is there any way to change order of inherited fields in inspector? 0 Answers