- Home /
Prefab around a object
I have a scene with a body maked with makehuman, and I need to add a simple prefab (a torus) around the arm of the body when the user touch the arm.
I tried:
Instantiatethe prefab in the point where the user touch, but the prefab apear in the border of the arm.Instantiatethe prefab in the center of the arm, with this code:
float radio = hit.transform.collider.radius; // the arm has a capsuleCollider Ray r = Camera.main.ScreenPointToRay(Input.GetTouch(0)); Vector3 origin = r.origin; float distance = (origin - hit.point).magnitude; RaycastHit ou; Vector3 position = hit.point; Ray r2 = new Ray(r.GetPoint(distance + 10f), -r.direction); if (cc.Raycast(r2, out ou, distance + 10f)) position = (hit.point + ou.point) / 2;
Instantiate(Prefab, position, Quaternion.identity);
This try to:
Select the center of the arm and initialite a torus.
The second option works in some cases, but the general impression is that is the wrong way to do it.
How can I add a prefab around a collider? or, how can I modify the mesh to add a visual indicator?
Your answer