how to select and drag .fbx object in unity by C# script
I'm using onMouseDown event to record the mouse position and OnMouseDrag event to change the position of the object which I selected. The following is the code,
void OnMouseDown() { screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position); offset = _trans.position - Camera.main.ScreenToWorldPoint (new Vector3 (Input.mousePosition.x, Input.mousePosition.y, screenPoint.z)); }
void OnMouseDrag() { Vector3 cursorPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z); Vector3 cursorPosition = Camera.main.ScreenToWorldPoint(cursorPoint) + offset; _trans.position = cursorPosition; }
========================================
It works fine with gameobject that create in unity, but not working with the .fbx/.3ds model in the scene. Can anybody know how to make it works for .fbx/.3ds model? Thanks in advance!
Answer by Joyetta · Sep 11, 2015 at 07:24 AM
I know it. The fbx model needs a collider component.
Your answer
Follow this Question
Related Questions
disable and enable a script on multiple other game objects 0 Answers
Rotation to a .fbx model ...... on click rotation 0 Answers
How does one instantiate a prefab with velocity? 1 Answer
Editor crashes immediately 0 Answers
Operator `*=' cannot be applied to operands of type `UnityEngine.Vector3' and `method group' 1 Answer