How to make an Interaction Feature (Unity Tutorial)

Поділитися
Вставка
  • Опубліковано 22 кві 2021
  • Project Files available now on Patreon for our patrons!
    / jtagamesinc
    JTAGames is unfortunately closing it's doors. Jon-Tyrell (The guy who's voice you hear 90% of the time) is moving to "Keahunui Technologies" An unofficial company / branding owned exclusively by himself.
    Thank you for your support the tutorials will remain on this channel.
    Please wishlist Keahunui technologie's first game on steam!
    store.steampowered.com/app/15...
    If you're feeling super supportive of Keahunui Technologies consider checking out Kickstarter.
    www.kickstarter.com/projects/...
  • Ігри

КОМЕНТАРІ • 143

  • @EmilJoes
    @EmilJoes 2 роки тому +13

    Super effective and flexible way to make interaction systems instead of having a lot of different scripts with different rays sending out to different things. Thanks for the tutorial :)

    • @ruhitrai6015
      @ruhitrai6015 2 роки тому +2

      How it efficient bro ? It using update method each frame

    • @jolinanturis3166
      @jolinanturis3166 Рік тому

      @@ruhitrai6015 How is it gonna work? To make the script work, you'll need the update function, sure not the most effective, but still more effective than well making millions of scripts for different things.

  • @markflakezCG
    @markflakezCG 2 роки тому +1

    Thanks! I'm a beginner and made it first with colliders but that was not good at all. Now it feels good.

  • @chanrachael4628
    @chanrachael4628 2 роки тому +2

    I'm beginner and I totally understand, thank you so much for the great tutorial

  • @khurum
    @khurum 10 місяців тому

    this is so easy I watched a ton of videos but none explained like that many thanks

  • @harry6270
    @harry6270 2 роки тому +1

    Great tutorial! I learned a lot.

  • @TheWobiz
    @TheWobiz 3 роки тому +7

    Really nice tutorial! straight to the point, i would love more tutorials about Horror Games

    • @JTAGames
      @JTAGames  3 роки тому +2

      Our goal is to waste as little of your time as possible so you can get back to developing. Anything specific in mind for horror game tutorials?

    • @TheWobiz
      @TheWobiz 3 роки тому +2

      @@JTAGames I would love something like reading notes, flashlight, Keys or codelocks, following Ai, everything would help! 😊

  • @shaheentechnologies4649
    @shaheentechnologies4649 3 роки тому +1

    You earn my sub

  • @omengaming2019
    @omengaming2019 2 роки тому

    Awsome sir!

  • @ParsTajicAfghan
    @ParsTajicAfghan 7 місяців тому

    thank you best tutorial i have

  • @BigToeDev
    @BigToeDev 3 роки тому +4

    Great tutorial man! Clear and straight to the point! Thanks for helping us out :D

  • @suitNtie22
    @suitNtie22 2 роки тому

    How would I make a bool Toggleable in this? Like say if I want an object to toggle between two materials every time I click on it?

  • @BERKACE
    @BERKACE 2 роки тому

    I'd love to see a tutorial using this system on a typical walking simulator mechanic: a paper that you can click on and then have it pop up on the screen so the player can read it

    • @JTAGames
      @JTAGames  2 роки тому +1

      I might do this a UA-cam short

  • @heyreefes
    @heyreefes 3 роки тому +1

    damn this good

  • @AndreaLPM1
    @AndreaLPM1 3 роки тому +2

    Nice tutorial and very helpful. Question: What would be the best to manage lets 100 interactable objects?

    • @JTAGames
      @JTAGames  3 роки тому +2

      This method works fine for 100+, probably even 1000+ I've already used a less refined version in a commercial game with 100+ interactables a while back.
      store.steampowered.com/app/1382180/Escape_Knox_Manor/
      What's cool is that each interactable doesn't actually do anything they just store information and the interactor script does all the work, along with Unity's event system.
      you'll be limited by having too many game objects with mesh colliders long before interactables slow you down.
      Let me know if you have any other questions!

    • @AndreaLPM1
      @AndreaLPM1 3 роки тому

      @@JTAGames Thanks for your answer and the example ahah ! Keep on with this yt channel.

  • @The3DCubeS
    @The3DCubeS Рік тому

    Hi, how would I make this work in 2d? What do I put the Interactor script on?

  • @darkdoom907
    @darkdoom907 2 роки тому

    How is the animator controller setup, can someone please tell

  • @mostafamo1315
    @mostafamo1315 Рік тому

    How would u write the code if i want to select the game object and rotate it then deselect it and it goes back to place

  • @FortressVOfficial
    @FortressVOfficial Рік тому

    4:55 leaving a mark

  • @warehouse1292
    @warehouse1292 Рік тому

    1000th Subscriber

  • @Marcieman
    @Marcieman 2 роки тому +2

    Thanks got it sort of working but am left with the animation as certain stuff is not explained and missing which makes this tutorial frustrating. Text size to resolution is just too low; have to go to full screen to read the text. Code is shown for a really short time and sped up a lot. Somewhere we had to write code and delete it one moment later without any reason why we wrote it in the first place (I dont mean the unity events or the logs). "Just simply put in the animator we made", which animator we made? Nowhere to be found, let alone the sprites which are also referenced to as that 'we' made it earlier in the tutorial, which we didn't... I think I am missing some sort of other part that goes beforehand. Sorry for my rant, not a personal attack as I do appreciate that you took the time to explain this!
    For anyone else to keep them from getting frustrated; here is the code. Forgot to mention anyone else reading; you have to make a Canvas and create a new object called 'image' in order to add the image in Interactable (also missed out on explaining that).

    • @JTAGames
      @JTAGames  2 роки тому

      Animation was not apart of the tutorial. It was just the interaction. Also what text size?

  • @himiko4202
    @himiko4202 2 роки тому +1

    After adding the first interactor script to my camera to test it, my game just no longer starts unless i remove the script.
    Edit: I fixed it, i'm not sure why it didnt work exactly but i edited the code to basically say the same thing but in a different way.
    void Update()
    {
    var ray = new Ray(this.transform.position, this.transform.forward);
    RaycastHit hit;
    if (Physics.Raycast(ray, out hit, 50, interactableLayermask))
    {
    Debug.Log(hit.collider.name);
    }

  • @v-rdays7525
    @v-rdays7525 3 роки тому +1

    Can you make tutorial like this but in blueprints Bolt,something like this

    • @JTAGames
      @JTAGames  3 роки тому

      Ive got to learn bolt first lol. Yeah I'll look into it. It might be a while though.

  • @estusmedia1887
    @estusmedia1887 2 роки тому +6

    Hi, is there any way you can make this project downloadable at all? At times you cover things without actually explaining how it is set up, for example the door frame already having an animator, having different animation states such as Opened and Closed, and also the sprites setup. I managed to get the sprites setup working but animation is something I struggle with and either a clearer breakdown of how this was all set up or access to the project folder would really be helpful.

    • @JTAGames
      @JTAGames  2 роки тому +1

      Projects not for download but when I have time I can make a tutorial tackeling animation and animators with this set up as the example.

  • @supersentaimexicano1967
    @supersentaimexicano1967 Рік тому +2

    For future tutorial videos it would be hugely apreciate if u show not only the code but also the setup of the scene. I got lost a lot when I had to asign images and sprites to the project.

  • @netherite5974
    @netherite5974 Рік тому +1

    how to open door with a key if you have key

  • @TatsukiBaba
    @TatsukiBaba 2 роки тому

    how to make a crosshair pick up items

  • @Reddatar
    @Reddatar 3 роки тому

    For the Game Jam can we modify some of the code or does it have to be the same as the tutorial

    • @JTAGames
      @JTAGames  3 роки тому

      It can be modified! As long as it's recognizable as being from this tutorial you'll be fine. So pretty much a raycast using unity events. Get creative! I'm excited to see what you come up with.

    • @Reddatar
      @Reddatar 3 роки тому +1

      @@JTAGamesok thx

  • @Rokyloreq
    @Rokyloreq 3 роки тому +1

    Nice video but can you give us the interaction hand?

    • @JTAGames
      @JTAGames  3 роки тому +3

      Sure. I'm working on a website and it's no where close to being ready but I can put the UI asset there for free. I'll comment here when it's up.
      EDIT: jtagamesinfo.wixsite.com/jtagames
      This is the beginning of the website we're working on. If you want the hand Icon just go to "Assets" page and click download you'll get a zip file with the single PNG.

  • @antonzhavner1750
    @antonzhavner1750 2 роки тому

    Cool friend. Your channel is excellent. I am still a beginner. Is this system suitable for mobiles?

    • @JTAGames
      @JTAGames  2 роки тому +1

      Yes! Follow this tutorial first then follow our most recent mobile control tutorial and at 8:46 in the mobile control video It shows you how to combine this with the mobile controls.

    • @antonzhavner1750
      @antonzhavner1750 2 роки тому +1

      @@JTAGames thanks👍

  • @cecavacd
    @cecavacd 2 роки тому +2

    How do I do it with tmp text? Instead of images I want to add text.

    • @JTAGames
      @JTAGames  2 роки тому

      It’s essentially the same but I would recommend keeping the image function and beneath it have a tmp text ui reference and a public string on on the interactable that changes that ui text and have it turn off and on at the same time as the image. Hope that made sense

    • @Psychopox
      @Psychopox 2 роки тому

      instead of doing public Text text, do public TMPro text;

  • @gemivr
    @gemivr 2 роки тому +1

    Can I have a link to get the code from

    • @JTAGames
      @JTAGames  Рік тому

      www.patreon.com/JTAGamesInc Project files to this tutorial and eventually all of our tutorials are available to our patrons on Patreon.

  • @evangelia941
    @evangelia941 2 роки тому

    Great tutorial, however it does not work in my scene. I saw that you have set up a canvas which includes the eventsystem in it...should we all have a canvas in our scene for the script to work?

    • @JTAGames
      @JTAGames  2 роки тому

      Yes

    • @evangelia941
      @evangelia941 2 роки тому

      @@JTAGames thank you!! Do you maybe have a tutorial on how to add the canvas etc from the beginning?

    • @JTAGames
      @JTAGames  2 роки тому +1

      @@evangelia941 I do not. However, I can give a brief explination.
      Right click in the hierarchy, go to UI, and click on image. That will be your interact image. Adjust it's size to your preference.
      You shouldn't need anything else from UI

  • @cepfathir7829
    @cepfathir7829 2 роки тому

    Nice, btw , can you make a interact with outline?

  • @mitnick2512
    @mitnick2512 Рік тому

    I love this script and think it works very well, however I've noticed an issue. You can interact with objects through walls, is there any way to fix that?

    • @JTAGames
      @JTAGames  Рік тому

      Put default in the layer mask as well. It shouldn’t break anything since it still checks for the script.

    • @mitnick2512
      @mitnick2512 Рік тому

      @@JTAGames I had already fixed it but thanks!

  • @marvicaaronlequin982
    @marvicaaronlequin982 2 роки тому

    Tried to follow the code but it does not help me when it reaches the LayerMasks. I copied the code front and back but it does not do anything for me

    • @JTAGames
      @JTAGames  2 роки тому

      Have you made the layermasks in the editor? If so are they spelt the same way?

  • @arandomcookie
    @arandomcookie Рік тому +1

    Hi, I'm back again. How can I call a specific Unity Event using the interaction system?

    • @JTAGames
      @JTAGames  Рік тому

      ? By adding it to the interactable? What do you mean?

    • @arandomcookie
      @arandomcookie Рік тому

      ​@@JTAGames I mean like: If you interact with this object, an event is called and other scripts will activate.
      Another thing is: Is it possible to create a variations in one object? For instance: tapping a button once to turn it on, and tap it a second time to turn it off without using animations?
      If there's another video of yours that answers any of my questions, I'm sorry for the annoyance. I'm trying to make a game with no knowledge using only youtube videos to program specific parts as I go.

    • @JTAGames
      @JTAGames  Рік тому

      @@arandomcookie The script already does exactly what you’re asking. It does the same thing as setting up a button. To have different results I’d recommend using bools or iterating through events.
      Also I’d recommend reading documentation on Unity Events because using this as a method for interaction will take forever if you don’t have a firm grasp of Unity Events.

    • @arandomcookie
      @arandomcookie Рік тому +1

      @@JTAGames Ok! Thank you very much!

  • @timewastingenjoyer
    @timewastingenjoyer 2 роки тому

    Is there a way to use this system to transition the player between scenes?

    • @JTAGames
      @JTAGames  2 роки тому

      Yup! We have a scene change tutorial and you can call the scene change function via interact as opposed to having it triggered when you enter in the trigger

    • @timewastingenjoyer
      @timewastingenjoyer 2 роки тому

      @@JTAGames thanks!

    • @timewastingenjoyer
      @timewastingenjoyer 2 роки тому

      @@JTAGames The only problem I'm having with this is that I'm exiting the doors at the wrong angle, is there a way to rotate the player either just before or just after using the door?

  • @hersonmarco2052
    @hersonmarco2052 2 роки тому

    I made a button with the Interactable script to open a hidden door on the wall
    When I press this button, the parameter bool "open" toggles to true and the animation plays, but it doesn't actually play. The animator window says that the animation is playing when "open" is true, but in game, none of that is happening.
    I have no idea what is happening

    • @JTAGames
      @JTAGames  2 роки тому

      Is the door set to static?

    • @hersonmarco2052
      @hersonmarco2052 2 роки тому +1

      @@JTAGames yes.......
      it worked

    • @JTAGames
      @JTAGames  2 роки тому

      @@hersonmarco2052 Yeah I had the same problem for like 2 hours a few months before I posted this tutorial before I realized static can’t be turned on.

  • @jimking1000
    @jimking1000 2 роки тому

    Can you please explain how you hid the blue sphere? If I turn off mesh render, then the blue sphere doesnt appear after the green sphere has been interacted.

    • @JTAGames
      @JTAGames  2 роки тому +1

      When you click on the green sphere
      1. Blue sphere : activate game object
      2. Green sphere: deactivate game object.
      When you click on the blue sphere
      1. Green sphere: activate game object
      2. Blue sphere: deactivate game object.
      Make sure the events are in that order for the respective spheres

    • @jimking1000
      @jimking1000 2 роки тому

      @@JTAGames Sorry i must have not been clear, I meant in the first place how did u hide the blue sphere since in the scene tab you couldn't see the sphere at all.

    • @JTAGames
      @JTAGames  2 роки тому

      @@jimking1000 Okay I think I understand your question but maybe not, we’ll see. It was disabled in the hierarchy

    • @jimking1000
      @jimking1000 2 роки тому

      @@JTAGames Ohh that makes sense thank you. Last question is it possible to increase the range of when you can interact?

    • @JTAGames
      @JTAGames  2 роки тому

      @@jimking1000 @1:13 it says out hit, 2… increase or decrease the number in order to increase or decrease the distance.

  • @mariegrasmeier9499
    @mariegrasmeier9499 2 роки тому

    Thanks for the tutorial, looks great.
    I tried it with the Unity Starter Assets First Person Controller and it does not work. I tried the interactor script on the Main Camera, the PlayerFollowCamera and the Player Camera Root. Did not help.
    Guess the problem is here:
    if(Physics.Raycast(this.transform.position,this.transform.forward,out hit, 2, interactableLayermask))
    {
    Debug.Log(hit.collider.name);
    }
    Can anyone help?

    • @mariegrasmeier9499
      @mariegrasmeier9499 2 роки тому +1

      Now it works. The problem was that the distance = 2 was too small. Always check the scale of your world.

    • @evangelia941
      @evangelia941 2 роки тому

      thank you for this, mine does not work either, what distance you changed it to?

    • @mariegrasmeier9499
      @mariegrasmeier9499 2 роки тому

      @@evangelia941 In my case, I think I changed to 10. But it always depends on the scale of everything. In the end, you must play around with the values until it work. You could use this debug tool to draw a line and make the ray visible, so you will see where it hits (sorry, forgot the exact way to do it. It is like "Debug.Log" but something else instead of "Log"

  • @turtleproductions5900
    @turtleproductions5900 2 роки тому

    Can we get the script it is to small to see

    • @JTAGames
      @JTAGames  Рік тому

      www.patreon.com/JTAGamesInc Project files to this tutorial and eventually all of our tutorials are available to our patrons on Patreon.

  • @bangagus1703
    @bangagus1703 2 роки тому

    Can you make examine object tutorial?

    • @JTAGames
      @JTAGames  2 роки тому

      Like holding the object mid air and rotating it?

    • @bangagus1703
      @bangagus1703 2 роки тому

      @@JTAGames Yes, like that,I tried to make a system inspact but always failed

  • @vitominiello6561
    @vitominiello6561 Рік тому

    how can I add a cursor in my scene? As soon as you start the program, you can already see the cursor, how can I add one into my scene?

    • @JTAGames
      @JTAGames  Рік тому

      UI image center of the screen.

    • @vitominiello6561
      @vitominiello6561 Рік тому

      @@JTAGames it’s as simple as that? But if my camera moves, the cursor won’t follow it right?

    • @JTAGames
      @JTAGames  Рік тому

      @@vitominiello6561 UI isn’t actually in your game scene it only renders to the spot it’s at on the screen. Even if you don’t have a camera in the scene it’ll render. That being said it won’t work without the camera. But no it won’t move unless you change its settings.

    • @vitominiello6561
      @vitominiello6561 Рік тому +1

      @@JTAGames ok thank you really much!

  • @audunstolpe7408
    @audunstolpe7408 3 роки тому

    Nice Tutorial. Im having some issues related to the project structure and how to assign the interact icon. Any chance for a link to the code?

    • @JTAGames
      @JTAGames  3 роки тому +1

      Codes not your problem. Drag and drop the image into the inspector.

  • @RoxosonRx
    @RoxosonRx 2 роки тому +1

    NullReferenceException: Object reference not set to an instance of an object
    Interaction.Update () (at Assets/scripts/Interaction.cs:18)
    if (Physics.Raycast(Camera.main.transform.position,Camera.main.transform.forward, out hit,2,Interaction))
    how to repair this?

  • @ManMr.
    @ManMr. Рік тому

    Every time I start the game, the animation immediately loops to open and closed without any interaction. Ive got no idea how to fix it

    • @JTAGames
      @JTAGames  Рік тому

      You didn’t set up parameters for your animator.

    • @ManMr.
      @ManMr. Рік тому

      @@JTAGames Sorry for bothering you again, but I have set up the Open parameter and have the interactible set correctly, but the animation still goes by itself. I am new to all this, so Im probably missing something obvious

    • @JTAGames
      @JTAGames  Рік тому

      @@ManMr. You need to click on the little line on the animator window between your two animations and then then set the BlendTree Parameter to Open, False or Open, True respectively.

    • @ManMr.
      @ManMr. Рік тому +1

      @@JTAGames TYSM!

  • @mratech8396
    @mratech8396 2 роки тому

    you type so fast i can follow

  • @KineticProduction
    @KineticProduction 2 роки тому

    i want to interacted object for android like granny games

    • @JTAGames
      @JTAGames  2 роки тому

      Don’t know what granny games is but this works for mobile and we have another tutorial for that too! It’s the FP mobile controller video on our channel

  • @darkdoom907
    @darkdoom907 2 роки тому

    I have a problem when I open the door, it gets opened and closes automatically

    • @JTAGames
      @JTAGames  2 роки тому +1

      Make sure you set the opposite animation to go when the bool is false and the other when the bool is true. Likely one of them doesn’t have that set up so it just loops back

    • @darkdoom907
      @darkdoom907 2 роки тому

      @@JTAGames hey, thanks for replying, turns out the problem arises only with input system, I tried it with the old Input System and it works fine. Would u mind helping me with this error?

    • @JTAGames
      @JTAGames  2 роки тому +1

      @@darkdoom907 never used the new input system. If I get around to it I’ll let you know 👍 sorry about that

    • @darkdoom907
      @darkdoom907 2 роки тому

      @@JTAGames Its alright, I already know what's causing the problem, explaining in terms of the old input system, my input when i press down sets the bool to be true, but it also reads input when I release the button which causes the bool to become false, and if I keep holding my input, the door open animation gets triggered for like infinite times

    • @darkdoom907
      @darkdoom907 2 роки тому +1

      Update, i just went along with .triggered function of input system and it works fine

  • @pixelmusic7273
    @pixelmusic7273 2 роки тому

    can I use this for Mobile Phone?

    • @JTAGames
      @JTAGames  2 роки тому +1

      With some alterations yeah. I'm working on a tutorial for mobile games and this gets tacked on the end.

    • @pixelmusic7273
      @pixelmusic7273 2 роки тому

      @@JTAGames thank you

    • @JTAGames
      @JTAGames  2 роки тому +1

      @@pixelmusic7273 The tutorial is now posted. Follow that tutorial first and then this one. ua-cam.com/video/UkiXp1VzqQo/v-deo.html&t

    • @pixelmusic7273
      @pixelmusic7273 2 роки тому

      @@JTAGames thank you soo muchh

  • @vdzmhm
    @vdzmhm Рік тому

    I'm so confused what the f is a raycast and layermasks?!?!

    • @JTAGames
      @JTAGames  Рік тому

      I’d recommend learning a little more about unity before tackling this tutorial. A raycast is essentially a laser pointer and the red dot holds the information the script needs. Layermask is an ID system and in this case tells the script what the laser pointer can and can’t point at.

    • @vdzmhm
      @vdzmhm Рік тому +1

      @@JTAGames oh ok thank you very much!! 😀

  • @mratech8396
    @mratech8396 2 роки тому

    ur not explaining its hard to follow

    • @JTAGames
      @JTAGames  2 роки тому +5

      Try setting the playback speed to .75 the audio will be weird but it should be easier to follow

  • @arandomcookie
    @arandomcookie Рік тому

    Functioned great until I tried using the Interectable script in multiple objects. It just broke. I can only interact with 1 object that uses the script, the other ones just stop working. @JTAGames, what can I do?

    • @JTAGames
      @JTAGames  Рік тому

      I’ve never had that happen before to be totally honest. Is your interactor script properly switching its current interactable?

    • @arandomcookie
      @arandomcookie Рік тому

      @@JTAGames I am a firm believer of "Show rather than tell", so I made a quick video showing what is happening. If you can check it out and see if you can find the error, I'd appreciate it. (Please forgive the very rough video, I just want to get this solved as fast as possible) ua-cam.com/video/jgQhX0RASRs/v-deo.html

    • @arandomcookie
      @arandomcookie Рік тому +1

      @@JTAGames Happy ending to this whole situation: I re-wrote the entire thing and it works now!

  • @Daniel-tg3su
    @Daniel-tg3su 2 роки тому

    InteractIcon & iconSize are bugged, for the interacticon I get this -->
    'Interactable' does not contain a definition for 'InteractIcon' and no accessible extension method 'InteractIcon' accepting a first argument of type 'Interactable' could be found (are you missing a using directive or an assembly reference?)
    I have a Canvas and an InteractIcon in my hierarchie. Here is the piece of code.
    if (interactable.InteractIcon != null)
    {
    interactImage.sprite = interactable.InteractIcon;
    if (interactable.iconSize == Vector2.zero)
    {
    interactImage.rectTransform.sizeDelta = defaultInteractIconSize;
    }
    else
    {
    interactImage.rectTransform.sizeDelta = interactable.iconSize;
    }
    }

    • @JTAGames
      @JTAGames  2 роки тому

      Do you have a public sprite called interactIcon in the interactable script?

    • @Daniel-tg3su
      @Daniel-tg3su 2 роки тому +1

      @@JTAGames No I didn't, thank you!

  • @hannahhoward3402
    @hannahhoward3402 2 роки тому

    I'm getting an error whenever I get within the range to interact with the object, I'm not even interacting with the object just getting close to it.
    InvalidOperationException: You are trying to read Input using the UnityEngine.Input class, but you have switched active Input handling to Input System package in Player Settings.
    UnityEngine.Input.GetKeyDown (UnityEngine.KeyCode key) (at :0)

    • @JTAGames
      @JTAGames  2 роки тому

      You updated your input settings so it’s no longer compatible with with any “Input.get”
      I haven’t looked into the new input system so as of right now I cannot help much.

    • @leralix98
      @leralix98 2 роки тому

      you can allow both unity imput system to work at the same time in the setting, maybe it will help

    • @Pkai1000
      @Pkai1000 2 роки тому

      same

    • @Pkai1000
      @Pkai1000 2 роки тому

      just disable the new one.
      go to:
      edit>> project settings>> player>> active input handling>> input manager(old)
      took me a bit to figure out