title: Moving runtime created objects using c# in Unity
body: <p>I have created an object at runtime by using drag and drop and I am moving the object and resizing the object by using <code>Input.getmousebutton</code>.</p>
  
  <p>When I try to move object I am holding the mouse button and I can move it,   but when I release the button and move the cursor to the empty space and then click the mouse button, the object is moved here.</p>
  
  <p>This is my main problem, but I also have to move camera towards object for zoom view.</p>
  
  <p><strong>MyCode is:</strong></p>
  
  <pre><code>using UnityEngine;
  using UnityEngine.UI;
  using System.Collections;
  public class ClickAction : MonoBehaviour {
      //float distance=10;
      public GameObject gm;
      public string obj=null;
      public Destroyer destroy;
      //public MoveObject move;
      private Vector3 screenPoint;
      private Vector3 offset;
      void Update () 
      {
          if(Input.GetMouseButton(0))
          {
              if(gm)
              {
                gm.GetComponent&lt;GameObject&gt;();
                gm.transform.position=new Vector3(Input.mousePosition.x,Input.mousePosition.y,1);
              }
          }
          if (Input.GetMouseButtonDown (0)) 
          {
              Ray toMouse = Camera.main.ScreenPointToRay (Input.mousePosition);
              RaycastHit rhInfo;
              bool didHit = Physics.Raycast (toMouse, out rhInfo, 500.0f);
              if (didHit) 
              {
                  gm=rhInfo.collider.gameObject;
                  Debug.Log (rhInfo.collider.name+"--"+gameObject.name);
                  obj=rhInfo.collider.name;
                  //move.OnMouseDown();
                  //move.OnMouseDrag();
                  //Calling Destroyer script to destroy object
                  destroy.getName(obj);
              }
          }
          if (Input.GetMouseButton (1)) 
          {
              if (gm) 
              {
                  gm.GetComponent&lt;GameObject&gt; ();
                  //gm.transform.localScale += new Vector3(0.3F, .3F, .3F);
                  gm.transform.localScale = new Vector3 (Input.mousePosition.x, Input.mousePosition.y, 1);
              }
          }
      }
  }
  </code></pre>