Тёмный

Pinch to Zoom and Panning on Mobile in Unity 

Press Start
Подписаться 24 тыс.
Просмотров 30 тыс.
50% 1

In this tutorial I explain how to write a C# script that will allow you to pinch to zoom and pan around the screen for a mobile or touch screen device.
SUBSCRIBE: bit.ly/2Js78lE
============
In this video I will show you:
1:00 How to build a script to pan around the screen
3:07 How to zoom using the mouse's scroll wheel
5:13 How to zoom using the pinch technique
COPY & PASTE SOURCE CODE:
pressstart.vip/tutorials/2018...
MORE TUTORIALS:
pressstart.vip/unity-tutorials

Опубликовано:

 

26 авг 2018

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 75   
@pressstart6864
@pressstart6864 5 лет назад
Copy & Paste source code: pressstart.vip/tutorials/2018/07/12/44/pan--zoom.html
@nathanaelgazzard7989
@nathanaelgazzard7989 2 года назад
This is amazing, thank you so much! Clearly explained AND source code included. 10/10
@crossing_lears
@crossing_lears Год назад
First time I've seen your tutorial, you explain so clearly! Thank you for this good one!
@ajayvijayh
@ajayvijayh 5 лет назад
Very helpful and easy to understand.
@twgamesindiedev7394
@twgamesindiedev7394 Год назад
Great video everything working perfect you save me a lot of time reading unity manulas and write code frome scratch now need just few small change to fit and work with my game.
@9247suresh
@9247suresh 5 лет назад
Thankyou for the tutorial.
@giovanniloreti
@giovanniloreti Год назад
Very good to explain the process of coding! Thanks so much
@zeheisty
@zeheisty 3 года назад
Such an underrated channel.
@sultanrahil3380
@sultanrahil3380 День назад
Very Helpful. Thank you
@unixcorp_siannas1452
@unixcorp_siannas1452 Год назад
Thx for sharing! Its very helpful for me
@random_precision_software
@random_precision_software 10 месяцев назад
Great tutorial simple explanation.
@SuperTieX
@SuperTieX Год назад
Hello could you explain please how to set max position for x , y since it goes over the map
@EpiccNoobyNotHere
@EpiccNoobyNotHere Месяц назад
thanks, rlly helpful.
@well5832
@well5832 3 года назад
nice works perfectly
@michaeld4083
@michaeld4083 5 лет назад
Muito obrigado do seu mais novo fã do Brasil!!
@pafnuteus
@pafnuteus 3 года назад
Thanks for the tutorial. There is one thing that' really missing here. it's good to have deceleration when you release your finger on panning. Can you give me a clue how to make it?
@jesuslopezpoveda1410
@jesuslopezpoveda1410 3 года назад
Awesome Content!, you should get a lot more subscribers and likes
@martin-gaming
@martin-gaming 4 года назад
How to make limited camera move (just from x=0 to x=60) and disable Y (no up and down just left and right)
@hc9196
@hc9196 6 месяцев назад
I am using the Adventure Creator plugin and this does not work. I suspect something is overriding it. Any idea how to solve this?
@matthewdenny3134
@matthewdenny3134 5 лет назад
Thanks man I've subbed :), I'm trying to work out how to add bounds to the camera movement with the Mathf.clamp but I'm not having much luck. Do you know the best way to do this?
@introvertskeleton4523
@introvertskeleton4523 4 года назад
just use an if statement if the camera has gotten to a particular position don't move.
@gameunity3d95
@gameunity3d95 Год назад
thank you ! how to limit camera in image bro ?
@davefranco7249
@davefranco7249 5 лет назад
is this work on ar camera?
@tiebevermandel1895
@tiebevermandel1895 Год назад
Does it also work in 3D? Or only 2D?
@venelinspiridonov7
@venelinspiridonov7 3 года назад
Hey man, congrats on the good video! Can I have the IconLoader.c# file from somewhere?
@mishahere
@mishahere 2 года назад
I copy pasted the code and unfortunately it doesn't do anything when I run the game
@nicklol7878
@nicklol7878 Год назад
Does this work in a 3D scene
@josaalbertomedranolara3070
@josaalbertomedranolara3070 4 года назад
Hello, it is a good video and it is very helpful!!. I have a doubt, how could we limit the area for the pannig script?
@ebmpingu
@ebmpingu 2 года назад
Lol 😂 that’s where the real problem is
@ebmpingu
@ebmpingu 2 года назад
I wrote a condition to use the touchStart as the limit try see if it works for u
@ebmpingu
@ebmpingu 2 года назад
Or just clamp the movement with Mathf.Clamp or Vector3.clampManitude see wat works for u
@teminal7189
@teminal7189 Год назад
@@ebmpingu We can hope he found his answer in the past 2 years😅
@shoopi1234
@shoopi1234 5 лет назад
Great and clearly explained. Too bad you didn't talk about setting bounds.
@pressstart6864
@pressstart6864 5 лет назад
You might find this video helpful: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-ailbszpt_AI.html
@sorayaanvari5906
@sorayaanvari5906 Год назад
When I build the project with graphQL, this is not working :((
@smartshopuk4234
@smartshopuk4234 3 года назад
For some reason this is not working, not even got any errors that will tell me why... Is this out of date by any Chance?>
@shung0209
@shung0209 10 месяцев назад
Thank you. This works fine for 2023. 🤣
@bhupiistersingh4097
@bhupiistersingh4097 4 года назад
The code works like a charm. However, there is one problem if you could help. As we zoom in and out on mobile, the moment we life one finger while other finger still on touch device, the camera pans to the location of that last touch still active. Its quite obvious that we cannot lift both fingers at the same time, there may be a lag of microseconds. Could you help with an improvement in script ?
@EpicSqu1rrel
@EpicSqu1rrel 4 года назад
Im having the same problem, did you manage to solve this?
@bhupiistersingh4097
@bhupiistersingh4097 4 года назад
@@EpicSqu1rrel Yes I did manage to solve this. But I used a different script. gist.github.com/bhupiister/dcdde0a6618fd847ed31824595604ed0
@bhupiistersingh4097
@bhupiistersingh4097 4 года назад
I have created two methods to disable and enable the script DeselectScript() SelectScript(), if you find it difficult to understand, you leave me a msg on git or here as well.
@EpicSqu1rrel
@EpicSqu1rrel 4 года назад
@@bhupiistersingh4097 thanks for the reply! I'll have a look at this asap :)
@EpicSqu1rrel
@EpicSqu1rrel 4 года назад
@@bhupiistersingh4097 Thats a brilliant script and works amazing for what i need! Ive added a clamp on the zoom though. // added new vars [Header("Zoom Level")] [Tooltip("Min and Max zoom levels")] public float zoomOutMin = 8; public float zoomOutMax = 18; // and changed this line to show clamping cam.orthographicSize = Mathf.Clamp(Mathf.Max(0.1f, cam.orthographicSize * oldDistance / newDistance), zoomOutMin, zoomOutMax); Again, thank you for this script! :)
@Diertstarr
@Diertstarr 3 года назад
How can I limit the panning to X and only to like -2 - 2 ?
@Luka-cr2ks
@Luka-cr2ks 2 года назад
Probably be too late but here is how. Camera.main.transform.position = new Vector3 ( Mathf.Clamp( Camera.main.transform.position.x, -2f, 2f), Camera.main.transform.position.y, Camera.main.transform.position.z );
@Diertstarr
@Diertstarr 2 года назад
@@Luka-cr2ks Never! Thank you!
@adarsh65kumar
@adarsh65kumar Год назад
Can u make a video to get the same functionality in ui?
@Mendogology
@Mendogology Год назад
It's the same thing. But if you don't want to mess with camera, you can use your desired UI element to scale to zoom in and out.
@sgtghost17
@sgtghost17 Год назад
I can't seem to get my scroll to be detected using input, just stays a zero?
@sgtghost17
@sgtghost17 Год назад
I was in simulate mode for mobile view, switched that back to free aspect and now scroll works. Guess that intentionally or unintentionally messes with inputs.
@khaitran4184
@khaitran4184 5 лет назад
thanks, it work, but how to change the zooming speed??
@pressstart6864
@pressstart6864 5 лет назад
Multiply increment by a float value
@FlashPaperGrind
@FlashPaperGrind 4 года назад
If you (or anyone reading this) still need a clearer explanation, this may help: add a public float under your zoomOutMax variable declaration, something like this: *public float zoomSpeed = 10f;* Then change the last line by multiplying the _increment_ by your float value: *Camera.main.orthographicSize = Mathf.Clamp(Camera.main.orthographicSize - increment * zoomSpeed, zoomOutMin, zoomOutMax);*
@EpicSqu1rrel
@EpicSqu1rrel 4 года назад
@@FlashPaperGrind thank you!
@suikasuika4157
@suikasuika4157 3 года назад
thanks a lot . For those who work on a 3D environnement do this instead : var mousePos = Input.mousePosition; mousePos.z = 50; then use MousePos instead of Input.MousePosition because in 3D you have to set the Z pos to your mouse of the calcul wont work.
@tiebevermandel1895
@tiebevermandel1895 Год назад
Thanks! You saved my day!👍👍👍
@tiebevermandel1895
@tiebevermandel1895 Год назад
it doesn't work with the pan zoom🙁🙁
@idzdigital3308
@idzdigital3308 5 лет назад
Bro..Please make JOCK DUMMY game tutorial..
@pressstart6864
@pressstart6864 5 лет назад
What specifically are you trying to learn?
@azmanbarraquias1681
@azmanbarraquias1681 5 лет назад
// I think its better if you can also include explanation comment in the source code.
@pressstart6864
@pressstart6864 5 лет назад
Azman Barraquias that’s what the video is for :)
@javier.sv89
@javier.sv89 5 лет назад
Dont work me
@pressstart6864
@pressstart6864 5 лет назад
It works bud, you just might be using the wrong camera type. This video is for Orthographic cameras. For perspective cameras, you should watch my other video: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-4_HUlAFlxwU.html
@FlashPaperGrind
@FlashPaperGrind 4 года назад
You should update this for Unity 2019/2020. Zoom seems to throw null errors.
@FlashPaperGrind
@FlashPaperGrind 4 года назад
Oh, nope, my bad. I created a new camera and left the Main Camera tag off so Camera.main doesn't work. Fixed now.