Clicking on a 3D object (Unity/C# tutorial)

  Рет қаралды 18,004

Mina Pêcheux

Mina Pêcheux

Күн бұрын

#unity #csharp #tutorial #gamedev #gameobject
In this short Unity tutorial, let's see how to interact with game objects at runtime, with 3 levels of difficulty!
🗒 Text version on Medium: / unity-shorts-2-clickin...
🔶 Unity docs: docs.unity3d.com
🔶 Unity's new input system: docs.unity3d.com/Packages/com...
0:00 - Introduction
1:03 - Credits
1:16 - Using OnMouseDown
4:34 - Using Physic Raycasts
6:29 - Tuning the Raycasts with layers

Пікірлер: 33
@kruth6663
@kruth6663 2 жыл бұрын
I love the format of these tutorials, thanks. Keep up the great work!
@minapecheux
@minapecheux 2 жыл бұрын
Hi - thanks you so much! I'm really happy you like it and yup, I don't plan on stopping for now, don't worry :)
@its_fabled
@its_fabled 2 жыл бұрын
Great tutorial and very pleasing to follow! :)
@minapecheux
@minapecheux 2 жыл бұрын
Thanks a lot :) I'm really happy you liked the tutorial!
@MuhsininMabrur
@MuhsininMabrur Жыл бұрын
i love mina voice
@leoarmanda9304
@leoarmanda9304 5 ай бұрын
me too
@DannyBoy443
@DannyBoy443 Жыл бұрын
Came for the tech, stayed for the accent lol
@leaf4645
@leaf4645 2 жыл бұрын
Thankyou! 😃
@minapecheux
@minapecheux 2 жыл бұрын
You're welcome, I'm really happy you like it :)
@rigolemus9250
@rigolemus9250 2 ай бұрын
merci!
@spacecowboy373
@spacecowboy373 Жыл бұрын
Managed to make my cube change color! My first game object I can interact with (outside of colliders). But how would you change the script to manipulate a specific game object to dissapear for example? Like a collectable.
@minapecheux
@minapecheux Жыл бұрын
Haha I'm happy I could help, great job! ;) For targeting a specific type of objects, you can do a few things: - either use the layers, as shown in the video (that's probably the most efficient, but perhaps you don't like using layers for grouping objects, it can feel a bit weird) - or raycast to anything (ie remove the layer, like in the first raycast example) BUT then check for a specific tag on your object, or even a specific name, or even a specific reference That's how you can "specialise" your raycast, if it makes sense ^^ Hope it helps, cheers!
@spacecowboy373
@spacecowboy373 Жыл бұрын
@@minapecheux I'll give it a try, thanks!
@Proviper666
@Proviper666 Жыл бұрын
I have a reference error! NullReferenceException.
@minapecheux
@minapecheux Жыл бұрын
Hello! I can try to help you debug if you want :) Do you have a bit more info as to where/when it happens? Where are you in the tutorial? What script/line does this error occur in (Unity tells you that in the console error log)?
@Kirb-B
@Kirb-B Жыл бұрын
im currently using the code form 3:20, and my click range doesn't reach far enough is there a way to extend this?
@minapecheux
@minapecheux Жыл бұрын
Hi! Hum, there shouldn't be any reach issue with this technique... are you sure you properly configured your scene with colliders and all? :)
@Kirb-B
@Kirb-B Жыл бұрын
@Mina Pêcheux yes im sure but I'll double check, thank you so much for responding!!
@minapecheux
@minapecheux Жыл бұрын
@@Kirb-B No worries - and btw if you want to send me details (either here or by email, at mina.pecheux@gmail.com), feel free to, I'd be glad to help more! :)
@kaloshabuthapa3284
@kaloshabuthapa3284 2 жыл бұрын
I followed all of your steps but my cube didn’t change color :(
@minapecheux
@minapecheux 2 жыл бұрын
First of all, thanks for taking an interest in my tutorial :) I'm sorry to hear you're having some issues! Do you have some errors in the Unity console? If you want, you can also share with me your current project (for example via email at mina.pecheux@gmail.com) - I'd be glad to have a look. Cheers :)
@kaloshabuthapa3284
@kaloshabuthapa3284 Жыл бұрын
@@minapecheux Thank you dear. XOXO
@jmas2593
@jmas2593 Жыл бұрын
Not working for me(3D) I don't know why Mine: -GameObject with SpriteRenderer -No Mesh -BoxCollider matches Sprite size
@minapecheux
@minapecheux Жыл бұрын
Hi there! Just so I understand your use case: which method are you trying to use for "clicking", among the 3 I showed? OnMouseDown, Raycast or Raycast+layers? If it's the Raycast, remember to check that you used Physics.Raycast in the code and a 3D BoxCollider (or alternatively Physics2D.Raycast and a 2D BoxCollider2D component)... I know I've made that mistake many times and it took me some time to see it ^^ Else feel free to give me more details so I can try and help! :)
@ilhambintang7547
@ilhambintang7547 Жыл бұрын
Miss i love you so much, you save me like dead ass. I was working on this for 6 hour just to make my object when i click it it make sound, and then your script 3:32 i literally understanding that code and yup my object when I click it it make sound. Im new to unity and c# shit but ay you help me literally. Thank you so much 🫡💜💜💜💜
@minapecheux
@minapecheux Жыл бұрын
Haha, I'm happy I could help and that you found the video useful! Cheers :)
@spugg713
@spugg713 11 ай бұрын
i used the second script and it does stuff when i click anywhere on screen, not just on object
@spugg713
@spugg713 11 ай бұрын
i changed _ray in pudate to comment one and it works properly now, thank you!
@minapecheux
@minapecheux 11 ай бұрын
Hmm not sure what could be the problem - have you checked you've probably assigned the layer to the objects, and also that the layer you're using in the script is the right one? :)
@aye.espinosa_
@aye.espinosa_ 5 ай бұрын
Hola! podría así mismo cambiar de scene a partir de clickear un objeto 3D????
@minapecheux
@minapecheux 5 ай бұрын
Hello! I'm not sure I understand the question... could you please re-detail it in English (or French)? :)
@aye.espinosa_
@aye.espinosa_ 5 ай бұрын
Excuse me, if I could change the scene from this point onwards. By clicking, for example, on a 3D model, go to another scene and by clicking on another object, return to the main scene.@@minapecheux
@minapecheux
@minapecheux 5 ай бұрын
Ah, got it! :)@@aye.espinosa_ Yep absolutely: you can use the callback of the click to run the logic you want - typically, to change the scene, you would use Unity's SceneManagement utilities, as shown in the docs/API over here for example: docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadScene.html Hope it helps!
📡 Understanding RAYCASTS! (Unity/C# Tutorial 🇬🇧)
8:42
Mina Pêcheux
Рет қаралды 2,8 М.
How I Made a 3D Platformer in 2D Game Engine
21:23
ggenije
Рет қаралды 444 М.
когда повзрослела // EVA mash
00:40
EVA mash
Рет қаралды 4,3 МЛН
Unity Tutorial: Open Panel on Button Click
3:39
Jayanam
Рет қаралды 170 М.
Learning C# In A Week... Otherwise I Fail University
9:04
How to Make 3D Fractals
7:48
CodeParade
Рет қаралды 1,6 МЛН
Making a Game With Discord's Bot API
10:39
PolyMars
Рет қаралды 2,6 МЛН
Learn to Build an Advanced Event Bus | Unity Architecture
13:27
Placing 3D objects on a Unity canvas
2:26
Tarodev
Рет қаралды 102 М.
The Formula for Replayable Games
18:44
Blargis
Рет қаралды 219 М.
Using AI to Create the Perfect Keyboard
12:05
adumb
Рет қаралды 1,4 МЛН
Здесь упор в процессор
18:02
Рома, Просто Рома
Рет қаралды 247 М.
Samsung Galaxy 🔥 #shorts  #trending #youtubeshorts  #shortvideo ujjawal4u
0:10
Ujjawal4u. 120k Views . 4 hours ago
Рет қаралды 3,3 МЛН
Hisense Official Flagship Store Hisense is the champion What is going on?
0:11
Special Effects Funny 44
Рет қаралды 2,9 МЛН