NEXT VIDEO: Design Patterns in Game Development 👉 kzbin.info/www/bejne/p4SVhIOiaKx4ac0
@lachlanroberto51603 жыл бұрын
I guess I am kind of randomly asking but do anyone know a good site to stream newly released series online?
@fisherzavier2283 жыл бұрын
@Lachlan Roberto i use flixzone. Just search on google for it =)
@breckenkoa44273 жыл бұрын
@Fisher Zavier Yup, been using Flixzone for years myself :)
@lachlanroberto51603 жыл бұрын
@Fisher Zavier Thanks, signed up and it seems to work :) Appreciate it !!
@fisherzavier2283 жыл бұрын
@Lachlan Roberto glad I could help =)
@hatrer2244 Жыл бұрын
I like that you show the bugginess before using the tag and not resetting the color on hit. Good work.
@mtgstudios15562 жыл бұрын
After much struggling I got this to work. From someone who has neither used C# or Unity extensively this has helped me out massively.
@zentergames16225 жыл бұрын
I like the environment you used
@FuzzyDPozzy4 жыл бұрын
a guy recommend me to learn raycast from this video , and guess what you just earned a subscriber!! I loved your tutorial man , you didn't let my attention go away. Thanks!
@N1ghtR1der6664 жыл бұрын
I enjoy the slower pace your videos go at so I dont need to pause every few seconds to keep up
@magicmamba4 жыл бұрын
4:46 i've had many a night like those after drinking...keep on coding! love the videos!
@Dbl_Plus_Good Жыл бұрын
Charles! Your videos are great my dude! The game dev community misses you. Hope you and your family are well. Be great!
@SnailSpaceWTF3 жыл бұрын
Hey, I'm pretty ignorantly at times. What's with the bold Unity Icon next to the UI and Environment in the Hierarchy? My mind is flagging that as interesting for some reason.
@Lycoon4 жыл бұрын
What if the selected object is a model? How to deal with the several materials?
@kyeperera75583 жыл бұрын
@GameProgrammerGalaxy Most 3D software will allow you to make multiple materials onto one through UV texture baking.
@ZoidbergForPresident5 жыл бұрын
5:40 THing is, an object can only have one tag, right? Depending on the complexity of the code and systems, what about writing an empty Selectable class and replacing the tag == selectable tag with GetComponent() != null ? Would that be acceptable? Also, wouldn't it be better to save the currently selected object's default material in order to restore it once unselected?
@lizkimber5 жыл бұрын
sure, but you can also do things by checking for components like GetComponent()
@Toocanzs5 жыл бұрын
Yea I think this is a much more maintainable way to do this
@InfallibleCode5 жыл бұрын
Absolutely! I’m going to address this when we refactor the code in the next video. I’m going encapsulate portions of the SelectionManager so that the methods for selecting objects, casting rays, and reacting to selection are interchangeable.
@ZoidbergForPresident5 жыл бұрын
@@lizkimber Isn't it what I proposed? :P
@GrashUriza5 жыл бұрын
I actually don't like the tag system and use components exactly as proposed. Most of the time, you want to do something with the component so the code looks like: MyComponent mc = gameObject.GetComponent(); if (mc) { MyComponent.Stop(); // hammer time! } Cool things in play: 1) Remember, scripts are componets, just like Camera, Transform, RigidBody, Renderer. This applies to the scripts you write as well. 2) If you dig through the MonoBehavior Inheritance, you will find Unity has set up so we can use a component reference as a boolean to check if its null. Saves us from writing " != null ". 3) When you are making a new script file, you are creating a new C# class. So the example above, I created a script called MyComponent. I can then make a variable to store it. When GetComponent is called on the object, I get a valid reference if it has it, otherwise I get a null reference. As you get better with c#, there are some other really useful and cool things you can do because your scripts are classes. 4) when you have compounded objects ( game objects that consist of multiple game objects ), I typically keep the script at the root. Something like colliders, end up as children. When I use this setup, I use GetComponetInParent instead.
@iwonwahyudi2 жыл бұрын
Can i apply this method to 3rd person controller view ?
@alexanderyankov6663 жыл бұрын
Hi there, running my progress at the fourth minute of the video(4:14) I get presented with this error: Object reference not set to an instance of an object. Can you assist?
@mistervoldemort75403 жыл бұрын
Did you fill the "highlight material" field in the inspector?
@mrsword64932 жыл бұрын
Had the same problem. My camera did not have the "MainCamera" tag.
@megusta49184 жыл бұрын
Nice tutorial, Only one thing u should change is row Camera.main... to public Camera cam; //make public variable, then assign a camera object to it private void Update() { cam.ScreenPoint... } The reason is, that if you will call Camera.main, its like Camera.FindGameObjectWithTag("Main Camera"); and this is bad.. Have a nice day!
@stegy134 жыл бұрын
Aye this helped me out thanks dude!
@megusta49184 жыл бұрын
@@stegy13 Glad to help :)
@benniegant4 жыл бұрын
LOL, I love this tutorial I just signed up! I sorry I gotta share my experience with you real quick LOL. 1.) My character "BOX" feel straight throught the floor after hundreds of attempts (2nd.) Rotating my Charcter cause rotation caos hundreds of time. lastly. my character bounce around and tumbled for ever :P so... 2AM CST It boiled down to the check boxes of the rigid body for its contraints and two rigid body on the character's animation controller and the rigidboy I added to my cute cube. Although this was painfully long in time. I really wanted to learn this so in the end I walked away with experience! LOL IM LVL UP! THANKS A MILLION #IC ;]
@jeanbibek75665 жыл бұрын
This is what I call tutorial !!! It's so good ! Thank you Sir !
@petelewis11722 жыл бұрын
Best line in history "Looks like I'm swimming in a pool of p!ss"
@DevhieDevlikesminecraft10 ай бұрын
it only works on the unity gameobjects but it dosen't work on the custom model for me , anyway to fix that? im not that good at making games btw
@JonTopping3 жыл бұрын
just a point for people that are learning, declaring everything "var" isn't really too helpful. it would be better more helpful (and better practice) to declare the variables as what they are. I'm pretty much a total noob, and I'm trying to learn what you're doing so I can understand, not just copy, so at 3:50 there's three variables that I don't know what they are, and I have to go digging deeper somewhere else to try and figure it out
@holdengreene97174 жыл бұрын
'Looks like im swimming in a sea of piss" that's when you went from informative to entertaining. Keep it up this helped me a lot.
@Driesipops4 жыл бұрын
thanks for the help... i was having trouble with brackeys older toturial and you helped me :D
@aarondavidlewis4 жыл бұрын
And if the selection was a button, how would I trigger an event on the button? Specifically - a UI button like the play/pause button on a worldspace video screen? I'm using Vimeo's Unity Package, but I can't figure out how to get the VimeoPlayer to play/ pause when selected by the Ray.
@mubsdeveloper45233 жыл бұрын
Best Tutorial Ever
@mikosz084 жыл бұрын
you look like Roman Bellic from GTA 4 also great tutorial
@TechLevelGames2 жыл бұрын
Very effective way to selected object! Thanks!
@hukudam3 жыл бұрын
Please help me! I have a problem with IPointerDown. I instantiate a prefabs like button, pressing the button for a few seconds it destroys. I disabled some raycast and it was ok, when doing some repair it started to fail. Some buttons created are not recognizing IPointerDown. I don't understand why.
@LemauDev3 жыл бұрын
how can i detect object while it is visible on screen and also with blocking system .... is there any refrence for that ? thanks
@nickmckenzie48273 жыл бұрын
If I understand this video correctly aren't you running GetComponent in every single frame ? i.e. if a mouse hovers over a selectable object you're hitting GetComponent every frame because it is in Update. I thought that was bad practice to do as GetComponent is quite expensive?
@mistervoldemort75403 жыл бұрын
Unfortunately yes. I was also concerned by the material assignment: in my understanding, when the object is hovered over, every single frame, the material is set to default, then to highlight. But we only see the highlight because the frame is rendered at the end of the update loop. So I think this must be pretty slow...
@zainsagar5 жыл бұрын
Awesome tutorial bro... ✌️😇
@sergeylebedev10523 жыл бұрын
Thank you, it was very convenient tutorial!
@InfallibleCode3 жыл бұрын
Glad to hear that!
@bronzekoala91414 жыл бұрын
Superb Tutorial! Just out of curiosity - why do you use the private keyword so often? Isn't private the default access modifier anyway? Is it for clarity?
@InfallibleCode4 жыл бұрын
That's exactly why. I prefer to be verbose by default just because I never know who may need to work with my code in the future.
@pulaksarkar7845 Жыл бұрын
Hello Sir, I can’t able to add information by clicking different parts of a 3D object. Please help me , and if possible make a separate tutorial on that.
@screeck4 жыл бұрын
Hi. i need to get name of any object i aim on with crosshair. I used this: string name = gameObject.name; in the begining of if(selection.CompareTag(selectableTag)) but after printing object name in console i see only "Selection Menager". Can someone help me?
@davdev7934 жыл бұрын
Hi. Nice and clean video .Any reason for not using functions like "onclick" and "onMouseOver" from monobehaviour? I saw a couple of people doing it your way but cant find the reason.
@ironoscar39484 жыл бұрын
rider looks amazing! and content too
@aboziad1003 жыл бұрын
hi thank you for your tutorial, and i have a question please what if i'm using this tutorial in Augmented reality what difference it will make in the design? thank you
@rifat92642 жыл бұрын
great man! works like magic thanks
@TigaLionessArt5 жыл бұрын
Hey! I have a question - what if I want multiple various default materials, can I add multiple tags and for each one there's going to be another default? If it's possible, how to code it properly so that it doesn't report some errors?
@Ketselle4 жыл бұрын
Is there any way to use the ray from an XR Ray Interactor as the ray in code line 10 instead of a ray from the main camera? I'd like to put this effect on objects that are pointed to by a hand controller in VR (specifically using the XR Interaction Toolkit).
@nazarivanechko39673 жыл бұрын
How do you add that red dot, is there a tutorial before this one?
@lordevilfishs3dprintingand1843 жыл бұрын
Create a raw image and drop in your cursor/dot then make it the child of the main camera, note. it will be part of the canvas. You can create the raw image by left clicking on the Hierachy and going to UI
@mr.secret5543 жыл бұрын
Thanks for the Tutorial. I have several objects in my project with different materials. How do I deal with them, so that each Object gets its default material back?
@ytmiva22 жыл бұрын
Store the default material in the object instead of in the manager. Then retrieve it from the object you're deselecting.
@rohitdoestech4 жыл бұрын
nice to see you using rider
@staceyantoinette22534 жыл бұрын
Code Adjusted for UI element :) using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class SelectionManager : MonoBehaviour { public string selectableTag = "Selectable"; public Camera Camera_Environment; // Ray Origin (Labeled Camera_Environment due to Layering Cameras) public GameObject UI_Interactable; private Transform _selection; // keeps track of current selection void Update() { if(_selection != null) { UI_Interactable.SetActive(false); _selection = null; } var ray = Camera_Environment.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { var selection = hit.transform; if (selection.CompareTag(selectableTag)) { UI_Interactable.SetActive(true); _selection = selection; } } } }
@veno85712 жыл бұрын
You are the best.
@sparrowhawk815 жыл бұрын
I wonder if you could get around some of those awkward null check statement using some null propagation from C# 6.
@InfallibleCode5 жыл бұрын
Oh yeah, I'm a sucker for syntactic sugar. I'll be cleaning up the code in a follow up video.
@sparrowhawk815 жыл бұрын
@@InfallibleCode sweet
@DavidB-rx3km4 жыл бұрын
@@sparrowhawk81 Does Unity C# support this?
@sadamps3 жыл бұрын
Well done. Pluralsight had similar bloated tutorial on this and is wasn't half as clear as yours. Subscribed.
@verdo84623 жыл бұрын
Hi, please tell me what is the script editor you are using
@vascobriz67474 жыл бұрын
Thanks very much for this tutorial!
@vinodkumarakula68075 жыл бұрын
Great tutorial. Which code editor and theme are you using?
@InfallibleCode5 жыл бұрын
I'm using Rider. I have an affiliate link in the description if you want to check it out and learn more about it.
@lucasbergin4392 Жыл бұрын
Not sure if this is a dumb question but what IDE do you prefer for unity?
@carolinacandelise66894 жыл бұрын
Hi! thanks for this tutorial! but how you set up the red dot?
@calebgunner3 жыл бұрын
Hi! For the red dot, you use UI. Simply make a canvas and select image (make sure sure the image is in the middle of the screen) Decrease the size of the image until it looks like a dot (you could use a circle for the image) Then simply change the image's colour to red.
@miltonsoto97335 жыл бұрын
men i have some problems, i make some GameObjects and save them as prefab item, but i can select them, its like the raycaster dont recognise them or can find them, i put a print to see some in console, but nothing appear so, have any idea about that?
@de0o03 жыл бұрын
Is this method optimal? This condition is happening every frame in update, there arent any better way to do that?
@janimations46522 жыл бұрын
hi, is it possible that instead of material to put in a partical when highlighted?
@allaze-eroler3 жыл бұрын
what happen if i use a texture renderer behind the second camera? that is kinda problematic i'm been having lately...
@mustafageo5 жыл бұрын
Better to just save the default material from the object itself before changing it. This would allow you have different material for each object.
@joshuareeves99855 жыл бұрын
Yes! How is this done?
@joshuareeves99854 жыл бұрын
@mikael englund Ah, thank you.
@virtualreality30732 жыл бұрын
comment on peut faire la meme chose mais avec XR RAy interactor
@BlueV2054 жыл бұрын
If I use multiple materials(For example, a cube was colored green and a sphere was colored red), how do I return them to their original materials?
@holamovie93434 жыл бұрын
this was super easy and helpful. thanks!
@garnishstudio35672 жыл бұрын
Thanks for the informative content! Any thoughts on how to modify the code to add different materials? This should be an obvious point, no?
@adequit Жыл бұрын
Look up a video focused on interacting with different GameObject Components, should work!
@__Rizzler__ Жыл бұрын
how bout adding an outline shader instead of changing colour?
@DiegoOliveiraProf4 жыл бұрын
nice, I did all my shooting mechanics using raycasts, now I am considering changing it to 'bullet.GetComponent().AddForce(mainCamera.transform.forward * 5000);' because I would like to see the bullet going forward :)
@josephboyer48285 жыл бұрын
I'm really confused about something. When we hover over a Selectable object, _selection grabs that information. So before we even deselect the object, isn't it true that _selection != null ? Therefore, shouldn't it be resetting to defaultMaterial and back to highlightMaterial over and over while we're hovering our mouse over the object? I must be missing something here. :(
@josephboyer48285 жыл бұрын
Oh wow it actually is doing this, I checked with a couple debug statements. So I guess this is just a rough start to this idea. Ok ok ok I'll go check out the other videos. :D
@karthiknallan5592 жыл бұрын
@@josephboyer4828 I know this was 3 years ago, but im struggling with this now lol, do you remember the solution for this problem?
@SpirusOfH4 жыл бұрын
How do you make it so that you can only select objects that are within a certain distance from the player? Like, I only want to be able to select an object if I'm standing close to it and looking at it, not if I look at it from across the room.
@katzekarlo23672 ай бұрын
very nice! thank you so much
@coverfaker83415 жыл бұрын
excellent video editing skills.
@rakibjahan5 жыл бұрын
Great video as always Charles! Setting the layermask when Raycasting results an increased performance, right?
@InfallibleCode5 жыл бұрын
Rakib Jahan yes, you’re correct. There are a number of ways to optimize the code for both flexibility and performance that I’ll be covering in the next tutorial.
@Postingyourvideos4 жыл бұрын
@@InfallibleCode Where is the next one ?
@SpicyCurrey2 жыл бұрын
@@InfallibleCode was this next video released? I can't find it
@kathyvdh55094 жыл бұрын
Is there a tutorial on how to set up this scene? Like what properties te objects have and stuff? (I'm a total beginner)
@zakilenck97594 жыл бұрын
thank you so much for the tutorial
@TackleProd3 жыл бұрын
I'm having trouble implementing this in my 2D platformer. I want to select a room on the world map. I'm using your code exactly, set up all the tags, but nothing works..... HELP?!?
@TackleProd3 жыл бұрын
I fixed it :) Turns out I cant use your code exactly since I'm making a 2D game :P
@MrFarkasOfficial4 жыл бұрын
fine. FINE. I`LL SUBSCRIBE!
@googleuser47203 жыл бұрын
Camera.main tho...
@konanws22285 жыл бұрын
How do I add a red dot? I made a script with a Raycast, everything works fine but the only element missing is the red dot and I have no idea how to incorporate it in my game. Thx bud
@mrtobi43995 жыл бұрын
me too ?
@michalrepovsky22085 жыл бұрын
@@mrtobi4399 #metoo
@Rishraff3 жыл бұрын
I have a question, how do you link the dot in the screen to the ray cast?
@JonTopping3 жыл бұрын
I don't believe that's the way it works. What's happening is the dot in the middle of the screen is just a UI object that is in the middle of the screen, and the ray is being shot out the middle of the camera, which is what you see as the middle of the screen. This means the ray will always be where the red dot is.
@mzadro74 жыл бұрын
Great video! Btw, what program are you using to write the scripts?
@InfallibleCode4 жыл бұрын
It’s called Rider
@jankystreams3337 Жыл бұрын
Hey, awesome video btw. I do have one question, however. When I look at objects that aren't selectable, they turn to the default material that I set. Anyway that anyone could help me out?? Thanks! Edit: I am a TOTAL noob at Unity, I started a couple days ago, so I am sorry if I seem a little stupid.
@montymonster4 жыл бұрын
What should I do if I only want to be able to select an item if I'm close enough?
@NoTAdrian1154 жыл бұрын
Is not better getting the default material from the raycast at the start? Because if you try to hightlight items each item will had his own material.
@JasonStorey4 жыл бұрын
well the ideal method is to use property blocks to change just the color of a single material instance, but that wasn't really the point of the tutorial.
@NoTAdrian1154 жыл бұрын
@@JasonStorey Well, I guess what the point was the Raycast but i wanted to ask.
@ernestosapienza37913 жыл бұрын
if I need to use this by clicking a button, would I need to change anything to this code? (the mouse is movable and not fixed with camera)
@borkyboy42863 жыл бұрын
A bit late but you could just setup a OnMouseDown and then put your if(selectionRenderer != null) inside
@ofthedrk7814 жыл бұрын
hey dude could you make a tutorial about raycasting with colliders
@pchead544 жыл бұрын
Thank you ... Now i can make a gun with raycast :D
@PrincessSleepyTV4 жыл бұрын
It's not working for me in Unity 2019 (Edit) It only works when I view one side of the object yet other sides don't register, the object is a simple unity cube with the correct collider. (Edit) For anyone else having this issue it has something to do with the lock cursor mode being on, not sure how to make it compatible with a centered cursor... any tips?
@dronehd-djimavicairfootage22954 жыл бұрын
maybe you can search how to set the mouse position to the middle of the screen. with the FPS controller is should actually do that automaticly though. good luck!
@ringostarkiller70975 жыл бұрын
useful video and great quality! thx u! :)
@aashutoshdabhade43254 жыл бұрын
Wil it work if i use screenspace canvas panel?
@ytmiva22 жыл бұрын
Thank you for pointing out the code needs to be refactored. If someone were to build more functionality into the same code it would become an unmaintainable mess. But it's great to quickly see some results! I was wondering if there is an advantage to using Tags instead of empty interfaces?
@HellBound_1013 жыл бұрын
But in addition to selecting the object with material, can you also enter the name of the object? Can this be done with a Text Canvas?
@aldigangster1234 жыл бұрын
Hey Charles! I'm wondering what you think about OnMouseEnter / OnMouseExit. Would you use it in a scenario like this, or are there cons which speak against it and more for the Raycast in Update() method? For example, couldn't the primitives in the example inherit from a "public class Selectable", which implements the OnMouseEnter logic, which in turn changes the material like in your example scene. Would this be more "solid", as the objects themselves contain the information on how to behave during mouse cursor interaction via inheritance, instead of relying on tags being correctly set in the end? Not at all criticism in any way, I'm just wondering what I should go for in my project. I was heading more to OnMouseEnter/Exit before I've seen your video and I'm not quite sure now.
@ivensauro3 жыл бұрын
In the video, he used these example to be simple, but on an shotter by example the raycast can be better (or not, this depend of your project)
@openingchain3282 жыл бұрын
What if a person wants to select multiple objects
@adwitrahman27624 жыл бұрын
my object becomes pink after deselecting. Whats the fix for that
@Josh7GAS4 жыл бұрын
How do you set up your visual studio 2019 IDE?
@noghost67973 жыл бұрын
You can look up in KZbin duh
@alexandergonzalez33763 жыл бұрын
how did you type that =/ sign?
@monkeyniples99853 жыл бұрын
you can use != in unity
@de0o03 жыл бұрын
Also I have one little question, what's the differnce between for example Ray declarations: "Ray ray" and "var ray".
@chonkgames3 жыл бұрын
Correct me if I’m wrong, but I think that if you are to use var, you have to immediately assign a value to it, and that way give it a type. And I believe it only works for local variables. My personal preference is to just go with Ray ray, but yeah, sometimes it is actually great for readability. Take a look at these two simple examples: 1. var dict = new Dictionary(); 2. Dictionary() dict = Dictionary();
@Rishraff3 жыл бұрын
Great video!
@RenderReady5 жыл бұрын
Love it!
@glalkia7133 жыл бұрын
Thanks man!
@tahsinxyz20374 жыл бұрын
What about Objects with diffrent materails ? How can we do same thing with diffrent objects ?
@samsaraAI20253 жыл бұрын
Just a simple question? You say that you are taking the mouse poistion to do the raycast, but this is not true, you are using only the center of the screen to do the raycasting. Is this not the same as Camera.transform.forward?
@Ytomany4 жыл бұрын
The guy in the thumbnail looks like William Riker from Star Trek tng
@xbix-31764 жыл бұрын
This doesn't work with HDRP in Unity 2019.4.3. Any ideas why?
@Trashboat10604 жыл бұрын
Renderer is render
@fragelius5 жыл бұрын
how would one use this for 3rd person view so item would highlight on mouse hover over object
@fragelius5 жыл бұрын
err never mind ... it was the typos in code :D
@MJ7202 жыл бұрын
Great tutorial. Think I'm doing something wrong as the selected material becomes purple (i.e. no material??). Work in progress I guess.
@alexanderthegreat74624 жыл бұрын
I wrote the whole code, but my objects dont turn back to normal when i dont hover over them