How to Make a Flexible Interaction System in 2 Minutes [C#] [Unity3D]

How to Make a Flexible Interaction System in 2 Minutes [C#] [Unity3D]

Rytech

1 год назад

78,364 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Leslie Mann
Leslie Mann - 11.09.2023 14:34

I am getting errors about script class not being found when I try to add the script. any advice?

Ответить
Samy
Samy - 23.08.2023 08:09

For those of You, If this didn`t Work, Try Like After writing full interaction code, then put the code in Main Camera and then, Reference Main Camera, Like By Dragging it in Hierachy, and after that, the function is all good to run,
Sometimes, There should be function which would need you to enable text like You can interact or Pickup or something,
For that case this is code, Directly in update, and then follow the same steps like creating interface and then reference it to the object script you want and that`s it
Ray rayEverytime = new Ray(interactionSource.position, interactionSource.forward);
if(Physics.Raycast(rayEverytime,out RaycastHit hitInfoEverytime, interactionRange))
{
if (hitInfoEverytime.collider.gameObject.TryGetComponent(out IInteractableEverytime internObj))
{
internObj.InteractEverytime();
}
}

Thank you for the awesome Tutorial

Ответить
Ficklestein
Ficklestein - 18.08.2023 20:47

Didn't work.

Ответить
DevilDrinksTea
DevilDrinksTea - 08.08.2023 20:18

Super helpful, thank you

Ответить
Lettuce
Lettuce - 23.07.2023 14:32

Can this be used in mobile? Thank you

Ответить
BanZ
BanZ - 20.07.2023 19:08

okay so im trynna do like an open locker door thing but when i make the animator do the open animation it goes okay, but when i try to close it, it still tries to open it even if its already open (i know this bc i also but a debug.log statment telling me if the door is opened and it always comes back as opened) so is there any solution to this?

Ответить
Fiery Ninja
Fiery Ninja - 20.07.2023 06:14

Great video, but how would I implement hover? Like it would say click e to interact if I am hovering over the object. Also how do I set up the InteractSource? Do I use the transform of the Camera? Finally what is a good number for the interactRange? Any answers will be greatly appreciated!

Ответить
Williampierre
Williampierre - 19.07.2023 17:11

I seem to be having an issue where Unity is telling me that InteractorSource.Position doesn't exist (at what should be line 22), could someone give me some pointers?

Ответить
Lucian BodnareSKU
Lucian BodnareSKU - 16.07.2023 17:07

Really helpfull tysm

Ответить
TideCTRL
TideCTRL - 10.07.2023 03:18

what do you put for the Interactor Source

Ответить
Brage
Brage - 09.07.2023 01:49

Suppose I use a coroutine with a WaitUntil that waits until F is pressed in my Interact. In that case, it will still execute when I am no longer looking at the object [which makes sense], any ideas on how I "cancel" the Interaction or the Coroutine after it´s started? Because I don´t want to do the whole ray-checking thing in my Interact scripts, as that would kinda defeat the purpose of the interface and would bloat scripts.

Ответить
Brage
Brage - 08.07.2023 23:38

If I add multiple Interactions to my Object it only executes the first in the component hirachie. Is there a way to execute all, cause I want to reuse these scripts on other objects say a sign and a note can both use text being shown on interaction.

Ответить
Emerald Skits
Emerald Skits - 04.07.2023 05:15

For anyone wondering, here's the code:

interface Interactable
{
public void Interact();
}

public class IntertheAct : MonoBehaviour
{
public Transform InteracterSource;
public float InteractRange;

void Update()
{
if (Input.GetKeyDown(KeyCode.E))
{
Ray r = new Ray(InteracterSource.position, InteracterSource.forward);
if (Physics.Raycast(r, out RaycastHit hitInfo, InteractRange)) {
if (hitInfo.collider.gameObject.TryGetComponent(out Interactable interactObj))
{
interactObj.Interact();
}
}
}
}
}

Ответить
Ingo McLean
Ingo McLean - 27.06.2023 16:06

Great job. One key difference between your videos and many others (not all but most): You explain how things are being used and why. This is great for knuckle draggers like myself

Ответить
Hüseyin Yeldan
Hüseyin Yeldan - 17.06.2023 12:59

your tutorials never work for me for some reason

Ответить
Some Stuff
Some Stuff - 15.06.2023 15:45

Sir. For this you got my sub

Ответить
Milzyy
Milzyy - 25.05.2023 05:36

How do I make it show text when I am in range?

Ответить
Jackson Blaize
Jackson Blaize - 12.05.2023 06:45

Why DOES NOONE EVER cop and paste the code into the comments and or the discription

Ответить
Dolph
Dolph - 05.05.2023 19:36

Why exactly did we add the interface?

Ответить
PugVRYT
PugVRYT - 02.05.2023 03:15

I don’t have some of the buttons for the script

Ответить
Canadian reviewer
Canadian reviewer - 29.04.2023 03:55

When I try to interact in game it’s not doing anything and I believe it has something to do the raycast as interact with the camera does not show the raycast

Ответить
LuckyBee
LuckyBee - 11.04.2023 21:14

what to put in interactorSource?

Ответить
Deleted
Deleted - 03.04.2023 21:57

wohhhoa

Ответить
LegoSol
LegoSol - 13.03.2023 22:30

thank you very much!!

Ответить
Maucaz alv
Maucaz alv - 10.03.2023 00:19

can I use it for a 3d person game?

Ответить
Emerald
Emerald - 08.03.2023 20:03

Thanks :D

Ответить
isacsimoes_
isacsimoes_ - 19.02.2023 04:33

Wow great video loved it.

Ответить
The Watcher
The Watcher - 04.02.2023 22:43

i just got back into coding and i used ur tutorial for picking up items, but I cant figure out how to make it to where the object faces the camera. Can anyone help?

Ответить
KalpolProductions
KalpolProductions - 05.01.2023 00:58

Dayumm, lmfao this was way better than creating an if statement for each object

Ответить
Aced Gamedev
Aced Gamedev - 04.01.2023 18:01

Thanks man, helped out a LOT with my game!

Ответить