Instantiate object (on touch position) by touch on the collider of other object
Hello, can you help me ^: How to instantiate object (on touch position) by touch on the collider of other object .It is a mobile 2d game ,and object whats will created more close to camera then the collider's , thanks :3 ok , i am done this script, but it is spawned object anywhere i touch - how to do that object can be spawned only on object's that is have this script area?
void OnMouseDown(Collision collision) { { RaycastHit _hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out _hit)) Instantiate(Prefab, new Vector3(_hit.point.x, _hit.point.y, _hit.point.z), transform.rotation); }
This is a bit vague... Can you add some more details in? Is this for mobile, are you trying to touch objects with hitboxes in the scene?
Answer by frufiGuild · Feb 05, 2017 at 06:24 AM
yey, i fixed this - all fine :3
void OnMouseDown() { { RaycastHit _hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out _hit)) Instantiate(Prefabii, new Vector3(_hit.point.x, _hit.point.y, _hit.point.z), transform.rotation); }