top of page

Drag and Drop objects using mouse

  • thetperson314
  • Jun 1, 2022
  • 1 min read

Updated: Apr 29, 2023

The code from the Drag and Drop tutorial




    Camera cam;
    Vector2 pos;
    bool holding;

    void Start()
    {
        cam = Camera.main;
    }

    void Update()
    {
        if (holding)
        {
            pos = cam.ScreenToWorldPoint(Input.mousePosition);
            transform.position = pos;
        }
    }

    private void OnMouseDown()
    {
        holding = true;
    }

    private void OnMouseUp()
    {
        holding = false;
    }


 
 

Recent Posts

See All

FAVORITES

Try playing Core Keeper and learn from it's sound design!

From the sound effect to the music - this is a masterpiece!

WHAT'S NEW?

New game on Steam and a new mobile video asset are soon to be published!!

I AM THINKING ABOUT

AI is on the rise. Being able to use it in the right cases and explaining the task correctly is no easy task but once you finish a full task without writing a line of code - your world will change!

CONTACT ME

Use any social media to contact me. For any question about programing and project I prefer using my Discord server, See you there!

© 2021 by Amit Klein. Nerd Head.

bottom of page