- Home /
After Drag a GameObject, Animation Changes
Initially the gameObject is running when i drag the gameObject its animstate should be changed as if it is hitting something now and i want to push it back to avoid hitting so then it should again be in running animstate after drag . But in my case some gameObjects are running and some are still hitting though some are being dragged .. one thing more i want that gameObjects should be running in different area so that after collision between themselves they should not be affected. this is the code kindly help me out. public GameObject enemy; private Vector2 velocity = new Vector2(-4,0); private Vector3 initPosi; public GameObject particle; public Vector3 offset; private Vector3 screenPoint; public Transform target; void Start () {
initPosi = transform.position;
void Update () {
if (Input.GetMouseButton (0)) {
Vector3 mousePos = Input.mousePosition;
Vector3 playerPos = Camera.main.WorldToScreenPoint( transform.position );
this.gameObject.rigidbody.MovePosition(mousePos);
Ray abc = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast(abc))
Instantiate(particle, transform.position, transform.rotation);
}
}
}
void OnMouseDown() {
offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
}
void OnMouseDrag()
{
Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
transform.position = curPosition;
}
Your answer
Follow this Question
Related Questions
turn OnMouseDrag on and off 1 Answer
How to implement building placement? 0 Answers
Moving around a weapon on screen using OnMouseDrag 0 Answers
How to make different actions using OnMouseDrag with two different colliders on one Game Object. 0 Answers
OnMouseDrag() distance traveled / delta 3 Answers