ไม่สามารถเล่นวิดีโอนี้
ขออภัยในความไม่สะดวก

Unity Tutorial : Drag Gameobject with Mouse

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 ส.ค. 2024
  • In this Unity Gamedev tip and tutorial I show how to drag a gameobject around in your scene while the game is running.
    I write a C# script that you can attach to you game object to have the drag feature.
    The script can be found here, you can use it in your won Unity projects:
    / unity-3d-drag-22917454
    See my social profiles here
    G+: plus.google.co...
    Twitter: / jayanamgames
    Facebook: / jayanamgames
    Patreon: / jayanam
    Production Music courtesy of Epidemic Sound: www.epidemicsou...

ความคิดเห็น • 242

  • @porkyz1
    @porkyz1 5 ปีที่แล้ว +85

    For those having issues make sure your camera for the scene is tagged as being "main camera", not as "untagged", the option for this is just under the name for the camera in the inspector panel.

    • @kiyano123
      @kiyano123 5 ปีที่แล้ว +2

      thanks!!!

    • @QQrest
      @QQrest 3 ปีที่แล้ว

      Thanks so Much!

    • @allfather_kree
      @allfather_kree 2 ปีที่แล้ว

      Thanks. It works but I am not sure why

  • @garethdenyer21
    @garethdenyer21 3 ปีที่แล้ว +5

    This is exceptional. Clear, fast, clean and massively useful. I'm now prompted to look at a lot more by the author.

  • @Yuzzel
    @Yuzzel 3 ปีที่แล้ว +8

    how to fix the objects clipping through the ground? while you are dragging it

  • @VictorAlmeidaTroo
    @VictorAlmeidaTroo 4 ปีที่แล้ว +1

    Just a little adaptation to fulfill my implementation and its working like a charm. Thanks a lot!!

  • @sandiechambers5540
    @sandiechambers5540 2 ปีที่แล้ว

    Omg, You star, you managed to solve my problem, thank you a million times over.!!

  • @Waarriorgaming
    @Waarriorgaming 3 ปีที่แล้ว

    Thanks For Help
    But I want to know How to move 3D object by touch dragging Finger By the screen means our object should follow our finger dirction

  • @NevilleMICALLEF
    @NevilleMICALLEF 3 ปีที่แล้ว +4

    Well done! It helped me to understand the concept in practice were now I can tailor it for my requirements. Thanks

  • @GBart
    @GBart ปีที่แล้ว +1

    Thanks for this, this was super clear and easy to follow!

  • @unityfuchs6610
    @unityfuchs6610 5 ปีที่แล้ว +3

    Thank you for the tutorial, but there is a small mistake in your script.
    If you pick your object up and let it loose, it lands correctly, in the same spot where you have picked it up, if your camera is NOT rotated, only. If you rotate your camera downwards, the script will do its job as it should but with the rigidbody attached, the object will fall straight down to the ground + the "rotationOffset" of the camera.
    For example: Your camera rotation is (20, 0, 0), your objectsPosition is (-10, 1, 0). You lift it up to "y = 9" and let go. You should notice, that the new coordninate is something like (-10.6, 9, 2.9) and not (-10, 1, 0), because it adds the rotation of the camera to it.
    The same problem occurs for cameraRotations in y and z.

  • @AstonArchitecture
    @AstonArchitecture 3 ปีที่แล้ว +7

    If anyone wants to stop movement along a particular axis, the easy way is to go into the rigidbody component of the object you're moving/dragging, and under constraints, "Freeze" the axis you don't want to use. :D

  • @rodneyapplebyphd
    @rodneyapplebyphd 3 ปีที่แล้ว +1

    Great explanation, quick and simple to implement.

  • @slmjkdbtl
    @slmjkdbtl 4 ปีที่แล้ว +5

    with this method, the calculated world position will have a fixed z value and the object will only move along x/y axis cuz you're using the clip space z value of the object to construct the vec3, but is there a way to make it have a fixed y value and the object move along x/z axis?

    • @jn1703
      @jn1703 4 ปีที่แล้ว

      I'd also very much like to know this

    • @slmjkdbtl
      @slmjkdbtl 4 ปีที่แล้ว

      ​@@jn1703 I solved by creating a plane and calculate the intersection between the play and the ray casted to the mouse position. E.g. if you want to use mouse to place an object on the ground, you can create a plane of normal vec3(0, 1, 0), then cast a ray from eye position to mouse, the intersection point would be the position of the object

    • @jn1703
      @jn1703 4 ปีที่แล้ว

      @@slmjkdbtl Thanks for your response but not sure I'm following, I have my camera rotated at 45 degrees and just want to move the object on these axis. How can I get the correct mouse offset to work with my objects current postiion?

  • @ValuFran
    @ValuFran 3 ปีที่แล้ว

    Thank you very much! I spent many hours tryng to do this but it didn't work, but this video did!! I'm very happy!

  • @qweasdy-pc6ql
    @qweasdy-pc6ql 2 ปีที่แล้ว

    Quick & easy to understand. Thank you very much.

  • @ilovegdragon
    @ilovegdragon ปีที่แล้ว

    OMG I finally found something that works! Thank you!

  • @zak-ks7ee
    @zak-ks7ee 7 หลายเดือนก่อน

    having an issue where when I drag the object... it just goes flying off screen
    my camera has to move around the world and I would like ti to be able to go from any position and pick up and drack the object into specific places... by when I run the code, it just seems to make the objects fly of into the void. anyone got any way to fix this?
    edit: so i simply copied the code and its seems to work now (slightly stange), but still face an issue with my camera moving with the object... it seems that the objects gravity is accelerated when i move my camera around
    edit2: also figured that out... have the rigidbody be set to zero when dragging

  • @sevenoel
    @sevenoel 5 ปีที่แล้ว +9

    Object can be dragged thru other objects floor etc, How 2 fix?

    • @zedgamedev
      @zedgamedev 5 ปีที่แล้ว

      Also looking for a fix

    • @TheDynamicDudes
      @TheDynamicDudes 4 ปีที่แล้ว

      u find a fix yet?

    • @mariocamspam72
      @mariocamspam72 4 ปีที่แล้ว

      @@TheDynamicDudes Add a 2D collider to the cube and floor, etc... and add a ground/collision check. Check out brackey's tutorial on that.

    • @ryana.9821
      @ryana.9821 4 ปีที่แล้ว

      need to incorporate collider components
      and onCollision events

    • @mariocamspam72
      @mariocamspam72 4 ปีที่แล้ว

      @@ryana.9821 incorporate is a cooking word

  • @jakubmajewski9080
    @jakubmajewski9080 4 ปีที่แล้ว +4

    i like it but the velocity keeps going up as the object is in the air, any way to make the velocity more realistic? everything goes through the ground

    • @aperm8834
      @aperm8834 3 ปีที่แล้ว

      add more gravity

    • @aperm8834
      @aperm8834 3 ปีที่แล้ว

      go to edit: project settings and add a (-0) value or a lower walue (+) means less (-) means

    • @DeezNuts-hy7qn
      @DeezNuts-hy7qn 3 ปีที่แล้ว +2

      @@aperm8834 that'll slow down the gravity of the entire game i suggest turning off Use Gravity in your draggable objects rigidbody when Mouse is down and turning it back one with the mouse button is up
      Good luck! @Jakub Majewski

    • @acompletelynormalrobloxgam7383
      @acompletelynormalrobloxgam7383 3 ปีที่แล้ว

      @@DeezNuts-hy7qn Thanks!! Really helped me!

    • @DeezNuts-hy7qn
      @DeezNuts-hy7qn 3 ปีที่แล้ว

      @@acompletelynormalrobloxgam7383 no problem

  • @fenzfendi
    @fenzfendi 4 ปีที่แล้ว +13

    physics while dragging? like it flops around when i drag it

    • @saiverx
      @saiverx 4 ปีที่แล้ว

      Maybe use the hinge-method that unityengine provides? Shouldn't be too hard creating a gameobject at the mouse-position connecting it to your object at the raycast-point where the mouse clicks. That will probably create the physics-effect you want :)

    • @naterivard
      @naterivard 4 ปีที่แล้ว +1

      @@saiverx You can also set `isKinematic` to `true` in `OnMouseDown` and reset it back to `false` on `OnMouseUp`.

    • @davydovua
      @davydovua 3 ปีที่แล้ว

      @@naterivard It will flop on gravity, but mouse movement itself will not create any force

  • @pyromaster9095
    @pyromaster9095 2 ปีที่แล้ว +1

    Tutorial is too quick, but after watching it several times i got it.

  • @CMichaelNeely
    @CMichaelNeely 5 ปีที่แล้ว +3

    Do you happen to have a similar tutorial for touch input?

  • @daryaf1742
    @daryaf1742 4 ปีที่แล้ว +3

    Hi, thanks for the great tutorial. But I'm having "Assets/DragFox.cs(23,23): Error CS0029: Cannot implicitly convert type 'UnityEngine.Vector3' to 'float' (CS0029)". It seems that mZCoord can't be float?

    • @daryaf1742
      @daryaf1742 4 ปีที่แล้ว +1

      apologies, I jst missed .z coordinate in this expression mZCoord = Camera.main.WorldToScreenPoint(gameObject.transform.position).z;

  • @esotericsean
    @esotericsean 5 ปีที่แล้ว +1

    Nice! I want to be able to pick up an object and have it "snap" to the center (position and rotation) so I can carry it around and drop it somewhere else in a first person game. What's the best way to do that?

    • @JayAnAm
      @JayAnAm  5 ปีที่แล้ว +1

      You want to snap it to the hand of the first person player?

    • @esotericsean
      @esotericsean 5 ปีที่แล้ว +2

      Jayanam Yeah, exactly! I wrote a simple script that lets me pick up objects and carry them around, but if they hit a wall they get off center. I also want the objects to rotate so they face the camera properly.

  • @scprepper2672
    @scprepper2672 4 ปีที่แล้ว +2

    Two problems/Questions. First, it's very sensitive. Is there a way to slow down the movement?
    Second, how can i lock the Y axis? I tried the obvious thing of freezing Y axis on its rigidbody but that didnt work.

    • @mtalha_k
      @mtalha_k 4 ปีที่แล้ว

      did you find a way to lock it? i need it too

    • @DeezNuts-hy7qn
      @DeezNuts-hy7qn 3 ปีที่แล้ว +1

      multiply the position by a float that is named smooth you can adjust it to your liking im not sure if this works but it should work
      Good Luck!

  • @NinjaddictFR
    @NinjaddictFR 3 ปีที่แล้ว

    Very nice and clear tutorial ! Thanks !

  • @guidocomba
    @guidocomba 4 ปีที่แล้ว +1

    Excelent Tutorial!!! thnx so much, that helps me alot!!! Regars from Argentina!!!

  • @joshuadrewlow
    @joshuadrewlow 2 ปีที่แล้ว

    Simple and working amazing still in 2022 :)

  • @EverythingRox
    @EverythingRox 5 ปีที่แล้ว +1

    Can somebody please tell me how to use the script on a prefab? My script is not working on the prefab.
    I am very very new to Unity and need help.

  • @Jiierf
    @Jiierf 4 ปีที่แล้ว +1

    How could I go about making the object stop once it hits a wall whilst dragging? Currently it goes through anything but if I collide with something it should just stop

    • @amritpatel3324
      @amritpatel3324 3 ปีที่แล้ว

      Hello I'm having same issue. If you have found any solution then please help me 🙏

  • @gamingrhys6413
    @gamingrhys6413 4 ปีที่แล้ว +1

    unity is throwing up errors like 'Assets\Drag.cs(14,19): error CS0120: An object reference is required for the non-static field, method, or property 'GameObject.transform' and Assets\Drag.cs(24,24): error CS0103: The name 'GetMousePosWorld' does not exist in the current context. please help

    • @rakhinaik1087
      @rakhinaik1087 4 ปีที่แล้ว

      For the second error check if your method name 'GetMousePosWorld' is exactly the same as where you are calling the method in 'OnMouseDown'.

  • @greatpinkwish
    @greatpinkwish ปีที่แล้ว

    really cool! many thanks!

    • @JayAnAm
      @JayAnAm  ปีที่แล้ว

      Glad you liked it!

  • @nuin9937
    @nuin9937 4 ปีที่แล้ว +3

    How would i limit the mouse to a specific area?

    • @nuin9937
      @nuin9937 4 ปีที่แล้ว

      Remixx i have completely given up on that lmao

  • @apricodegames
    @apricodegames ปีที่แล้ว

    İf when ı want to for mobile touch how ı can doit?

  • @teimurlu
    @teimurlu 2 ปีที่แล้ว

    How can I lock its movement to only the X axis and also stop when touching another collider (such as ground)?

  • @jansvec3855
    @jansvec3855 2 ปีที่แล้ว

    Is there any way how to move object only in two axis at once? Example: left mouse button move in X and Y and right mouse button move in Z and Y?

  • @nestori1337
    @nestori1337 3 ปีที่แล้ว +2

    As long as u hold the rock up with mouse it builds up acceleration with gravity, how can I fix this?

    • @bruhvioli
      @bruhvioli 3 ปีที่แล้ว

      did u ever find a solution for this?
      edit: i figured out a solution. turn off gravity onMouseDown like this:
      rb.useGravity =false;
      then turn it back to true on onMouseUp

    • @DeezNuts-hy7qn
      @DeezNuts-hy7qn 3 ปีที่แล้ว

      @@bruhvioli that was exactly what i was going to say

    • @iangraham6730
      @iangraham6730 2 ปีที่แล้ว

      I know this is old, but for anyone in the future, you can also set Time.timeScale = 0; when moving it, and back to 1 when the move is finished . . this is what I am doing in my poly bridge knock off, except I am using a button which I call "Play" to activate the time, the time is set to 0 on game play start.

  • @deangreasley8168
    @deangreasley8168 5 ปีที่แล้ว +1

    excellent tutorial, thanks for this !

    • @JayAnAm
      @JayAnAm  5 ปีที่แล้ว

      Thx, you're welcome

  • @valfareinwindir1258
    @valfareinwindir1258 5 ปีที่แล้ว +1

    How do you drag one object by clicking anywhere?

  • @mehmetbattal8772
    @mehmetbattal8772 4 ปีที่แล้ว +1

    Does this work for mobile(IPhone). I know it gets mouse input but i heard that mouse input also works with touch controls is that correct?

  • @SharkfightersSH
    @SharkfightersSH 3 ปีที่แล้ว

    I am having a little issue using this in on a boardlike scene. Moving the Object towards the player will cause it to move down and (potentionally) into the ground. Any soloutions?

  • @SarahAndreaRoycesChannel
    @SarahAndreaRoycesChannel 3 ปีที่แล้ว +2

    TH-cam is broken. 3 advertisements for 3 and bit minutes of video.

  • @cydoyk
    @cydoyk 4 ปีที่แล้ว

    Thank You!, I've been using this to make my fps game, at first i thought it was very hard to do, but then i realized just how easy it is only a few lines of code. Thank You!

  • @lora6938
    @lora6938 3 ปีที่แล้ว

    Can you tell me how to make the object by clicking the mouse become a little to the left or to the right, and releasing the mouse returned to the center as it was before clicking?(for kinematic)

  • @wildifin
    @wildifin 5 ปีที่แล้ว +4

    How to do this with 2D object

    • @jamesspeed3531
      @jamesspeed3531 3 ปีที่แล้ว

      works the same, if your using sprites - only use x and y and within the context of Vector2 instead of Vector3

  • @byter-exe2984
    @byter-exe2984 2 ปีที่แล้ว

    hey uhh... i want it to have collision with other objects while i hold it.. how do i?

  • @artjom5617
    @artjom5617 4 ปีที่แล้ว +1

    hmm why cant i "clamp" the y position instead of z?
    if i change the values simply to y, it just do not react when i try to drag it. but when i change it back to Z it works again :/

    • @user-iv5hl8gu4l
      @user-iv5hl8gu4l 3 ปีที่แล้ว

      I have a same problem It's driving me crazy please help me I'm crying My tears are making a lake

    • @artjom5617
      @artjom5617 3 ปีที่แล้ว +1

      @@user-iv5hl8gu4l uff sorry its already too long ago.
      i think i just keep searching for other solutions or i tried around with that one.. i dont remember

  • @joeaugustine4172
    @joeaugustine4172 ปีที่แล้ว

    Fantastic tutorial!!!

  • @thepotatogaming2340
    @thepotatogaming2340 4 ปีที่แล้ว

    Best tutorial ever

  • @utkarshpanchal400
    @utkarshpanchal400 2 ปีที่แล้ว

    Thanks buddy really really Appricaiated

  • @crab9852
    @crab9852 5 ปีที่แล้ว +2

    Do you know how to lock it so it doesn't move the object in the y axis?

  • @omar-0082
    @omar-0082 ปีที่แล้ว

    THANK YOU, you are amazing

  • @nokky070
    @nokky070 2 ปีที่แล้ว

    Does anyone know how to fix that the game objects can be dragged through walls and floors?

  • @shauryakumar306
    @shauryakumar306 3 ปีที่แล้ว

    Thanks a lot. Helped me a lot.

  • @MaruskaStarshaya
    @MaruskaStarshaya 2 ปีที่แล้ว

    Works as magic, thank you!

  • @jayantbarthwal4470
    @jayantbarthwal4470 5 ปีที่แล้ว +1

    thankyou very nice , it helped me alot.

  • @adamabbott2014
    @adamabbott2014 2 ปีที่แล้ว

    why the movement speed is so slow?

  • @canerkuncu9191
    @canerkuncu9191 5 ปีที่แล้ว +4

    nice tutorial thank you but i have a problem. when i dragged an object to a wall , it passes through the wall. i think i have to add velocity or something like that for dragging. but i dont know how to do it :/

    • @sevenoel
      @sevenoel 5 ปีที่แล้ว

      I want the same too

    • @dg_dotnet9616
      @dg_dotnet9616 4 ปีที่แล้ว +1

      VERY SIMPLE ADD THIS "mousePoint.y = 0;" TO GetMouseWorldPos() function
      this way you lock the y axis

  • @Boyke07
    @Boyke07 2 ปีที่แล้ว

    How can I freeze the y-axis while dragging whis this base code?

  • @QQrest
    @QQrest 3 ปีที่แล้ว

    Thanks! You really Helped Me For My Game!

    • @JayAnAm
      @JayAnAm  3 ปีที่แล้ว

      Glad I could help!

    • @QQrest
      @QQrest 3 ปีที่แล้ว

      @@JayAnAm :)

  • @timmytainment
    @timmytainment 5 ปีที่แล้ว +1

    Not working for me. Also no errors given... I use a cube with nothing else (no rigid body, throewable, etc)

    • @JayAnAm
      @JayAnAm  5 ปีที่แล้ว

      So you didnt add a rigidbody? Because you will need one 03:03

    • @timmytainment
      @timmytainment 5 ปีที่แล้ว

      @@JayAnAm hi. I tried at first with one

  • @azlanahmad4021
    @azlanahmad4021 2 ปีที่แล้ว

    what we do if we need to drag object on only x axis

  • @LordParcyval
    @LordParcyval 3 ปีที่แล้ว +1

    thanks but the object is rotating

    • @hansaxl9575
      @hansaxl9575 2 ปีที่แล้ว

      Constraint the rotation in the rigidbody setting

  • @gatzkerob
    @gatzkerob 4 ปีที่แล้ว +3

    My object disappears from the game window when I click on it. I logged the object coordinates in the console and it seems to be sending it way off screen. Unity 2019.2.18f1

    • @massiveleg
      @massiveleg 4 ปีที่แล้ว

      same

    • @massiveleg
      @massiveleg 4 ปีที่แล้ว

      nwm I copied the script from the desc and it worked

  • @letthatbe
    @letthatbe 2 ปีที่แล้ว

    I don’t understand shit since i am a beginner. But it works like a charm

  •  4 ปีที่แล้ว

    I need this for Super Mario 64 remake to stretch Mario head
    Bur, this script works on unity 2017?

  • @itskristis
    @itskristis 2 ปีที่แล้ว

    with the rock its bout drive its bout powa

  • @BrillFire
    @BrillFire 3 ปีที่แล้ว

    Translate please, почему одного ScreenToWorldPoint недостаточно для перемещения объекта, для чего нужен moffset, что это такое?

  • @artlab5724
    @artlab5724 4 ปีที่แล้ว

    Here script who want to lock gameobject by Y axis - pastebin.com/AV0cgtnu
    You can lock any axis you want

  • @dvndrsingh786
    @dvndrsingh786 5 ปีที่แล้ว +2

    so this script works fine for me!!!
    but can someone explain me what's happening?

    • @artjom5617
      @artjom5617 4 ปีที่แล้ว

      well, turn on the sound :D

  • @ezoca8272
    @ezoca8272 3 ปีที่แล้ว

    Anybody Knows how to add like a white drag line?

  • @theopoldthegamer4284
    @theopoldthegamer4284 3 ปีที่แล้ว

    Apparently Callback Executor needs to derive from Mono Behavior??? Help!

  • @umarfarooqbudihal2511
    @umarfarooqbudihal2511 3 ปีที่แล้ว

    Hey man...I love this
    I just wanna..know...how do I move the object by dragging along the path...
    ...help.plzzzz

  • @user-tf6ch1oj2m
    @user-tf6ch1oj2m 3 ปีที่แล้ว

    It works! Thank you!

  • @karolis4904
    @karolis4904 4 ปีที่แล้ว +4

    THE SCRIPT boyz
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class dragobiject : MonoBehaviour
    {
    private Vector3 mOffset;
    private float mZCoord;
    void OnMouseDown()
    {
    mZCoord = Camera.main.WorldToScreenPoint(gameObject.transform.position).z;
    //idk
    mOffset = gameObject.transform.position - GetMouseWorldPos();
    }
    private Vector3 GetMouseWorldPos()
    {
    //Y X
    Vector3 mousePoint = Input.mousePosition;
    // Z COORD
    mousePoint.z = mZCoord;
    return Camera.main.ScreenToWorldPoint(mousePoint);
    }
    void OnMouseDrag()
    {
    transform.position = GetMouseWorldPos() + mOffset;
    }
    }

  • @LeeTGame
    @LeeTGame 4 ปีที่แล้ว

    Short and sweet. Really nice video :)

  • @thezzxc9904
    @thezzxc9904 5 ปีที่แล้ว +2

    perfect! thanks!

  • @Gaboxf
    @Gaboxf 8 หลายเดือนก่อน

    Thank you

  • @franktout2741
    @franktout2741 4 ปีที่แล้ว

    I can get it to work but only if the objects are closer to the camera??? How can I get it to select distant objects (not that distant really)

    • @vanshtandon1829
      @vanshtandon1829 4 ปีที่แล้ว

      Check Here th-cam.com/video/FKEXWn68DSA/w-d-xo.html

  • @augustbjrnsti1232
    @augustbjrnsti1232 4 ปีที่แล้ว

    does this version work with visual studio code?

  • @cahydra
    @cahydra 3 ปีที่แล้ว

    Isn't this available in the editor already?

  • @maciekwolski
    @maciekwolski 4 ปีที่แล้ว

    Nice, thx to allow us easy copy past

  • @gildas6478
    @gildas6478 3 ปีที่แล้ว

    i'm using Unity 2020.1.10f1 and for some reason in visual studio code i got an error code C1513 } expected

    • @poggersguy3755
      @poggersguy3755 3 ปีที่แล้ว

      you forgot a closing bracket

  • @ShacharOz
    @ShacharOz 3 ปีที่แล้ว

    little question: how would you limit the object from being able to get dragged through walls?

    • @DeezNuts-hy7qn
      @DeezNuts-hy7qn 3 ปีที่แล้ว +1

      either raycasts or box colliders on your walls

  • @Daniken89
    @Daniken89 5 ปีที่แล้ว +1

    Thanks my dude!

  • @AidenTheRealShadowwolf
    @AidenTheRealShadowwolf 3 ปีที่แล้ว

    PERFECT NOW I CAN MAKE AN amnesia like door!

  • @fallendagger2766
    @fallendagger2766 4 ปีที่แล้ว

    Hey how can i move that only in x axis?

  • @m.bilalbark3682
    @m.bilalbark3682 4 ปีที่แล้ว

    Nice solution, thanks bro :)

  • @imrankkg5029
    @imrankkg5029 4 ปีที่แล้ว

    lifesaver Thanks man. God Bless You.

    • @JayAnAm
      @JayAnAm  4 ปีที่แล้ว +1

      Glad it helped

    • @Nacho-ms2pw
      @Nacho-ms2pw 4 ปีที่แล้ว

      @@JayAnAm Hey, do you have any idea what trs is at 1:57 my game isn't accepting it and I'm using 2018.4.

  • @shtml54
    @shtml54 5 ปีที่แล้ว

    Cool, It actually works.

  • @pwjxu11
    @pwjxu11 5 ปีที่แล้ว +1

    Hi Jayanam, how do i move 3d obj move forward/backward along z axis when mouse is up/down ,( currently in your video is show obj is move up/down when mouse is up/down)

  • @KJPiGames
    @KJPiGames 4 ปีที่แล้ว

    Why did I also do it my way didn't work ,but as soon as I took your implementation everything worked? Code one in one just like that minus 2 days:(
    SPS cel at least someone helped like

  • @NeatWolf
    @NeatWolf 4 ปีที่แล้ว +1

    Hi there!
    Could you please have a sample of this, but using IDragHandler and similar interfaces on a single object/class?
    I'm targeting mobile and don't want to use Mouse-related code, as it's considered a bad habit.

  • @poveaofc421
    @poveaofc421 3 ปีที่แล้ว

    Thank you so much

  • @erikm9768
    @erikm9768 4 ปีที่แล้ว

    Btw, you know you dont need to write gameObject.transform , just transform is fine, or this.transform

    • @JayAnAm
      @JayAnAm  4 ปีที่แล้ว

      :-) Yes, thx. But I found it a good practice for demonstrating that the gameobject has a transform.

  • @_g_r_m_
    @_g_r_m_ 3 ปีที่แล้ว

    Thank you so much man

  • @Fromtunnel
    @Fromtunnel 3 ปีที่แล้ว

    Thank you!

  • @andriibilych4983
    @andriibilych4983 4 ปีที่แล้ว

    Thank you good man!

  • @happytofu5
    @happytofu5 4 ปีที่แล้ว

    With that technique, you can drag the objects into the ground and into each other. Is there a way to avoid that?

    • @aperm8834
      @aperm8834 3 ปีที่แล้ว

      seme hapens in hello neighbor never join 2 cans in that game

    • @DeezNuts-hy7qn
      @DeezNuts-hy7qn 3 ปีที่แล้ว

      colliders or raycasts could help

    • @alfacedolidl6236
      @alfacedolidl6236 2 ปีที่แล้ว

      @@aperm8834 imagine asking? lol

  • @polkab6569
    @polkab6569 3 ปีที่แล้ว

    Thanks bro ! can you help pls i need delete Z and Y just move object on X

    • @thepotatogaming2340
      @thepotatogaming2340 3 ปีที่แล้ว

      You need to ad a rigidbody then go on constraint and freeze the position you dont want it to go on or rotation

    • @worthas7196
      @worthas7196 3 ปีที่แล้ว +1

      @@thepotatogaming2340 nope. that doesn't work, because the script ignores that.

  • @Sykkoss391
    @Sykkoss391 4 ปีที่แล้ว

    Clean, thanks a lot :)