- Home /
Generate Bounding Box, In Game
I'm trying to make it so when I pick up an object in game, it has a red bounding box indicating it's selected when grabbing and dragging it, but all I have atm, is making it draw a bounding box in the editor only. How could I go about making this affect the object in-game aswell?
Sorry, this message box seems to have screwed up my code format, hope you can understand what I'm doing with it
var _bIsSelected = true;
function OnDrawGizmos()
{
if (_bIsSelected)
OnDrawGizmosSelected();
//if(Input.GetMouseButton(1))
//{
//_bIsSelected = true;
//}
//else
//{
//_bIsSelected = false;
//}
}
function OnDrawGizmosSelected()
{
Gizmos.color = Color.red;
Gizmos.DrawSphere(transform.position, 0.1); //center sphere
if (transform.renderer != null)
Gizmos.DrawWireCube(transform.position, transform.renderer.bounds.size);
}
Comment
Add 4 spaces before each line of code if the formatting button doesn't work for you. Normally you can just select all the code and press 010101 button to format the code nicely for you.