Комментарии:
I am getting errors about script class not being found when I try to add the script. any advice?
Ответить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
Didn't work.
ОтветитьSuper helpful, thank you
ОтветитьCan this be used in mobile? Thank you
Ответить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?
Ответить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!
Ответить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?
ОтветитьReally helpfull tysm
Ответитьwhat do you put for the Interactor Source
Ответить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.
Ответить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.
Ответить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();
}
}
}
}
}
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
Ответитьyour tutorials never work for me for some reason
ОтветитьSir. For this you got my sub
ОтветитьHow do I make it show text when I am in range?
ОтветитьWhy DOES NOONE EVER cop and paste the code into the comments and or the discription
ОтветитьWhy exactly did we add the interface?
ОтветитьI don’t have some of the buttons for the script
Ответить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
Ответитьwhat to put in interactorSource?
Ответитьwohhhoa
Ответитьthank you very much!!
Ответитьcan I use it for a 3d person game?
ОтветитьThanks :D
ОтветитьWow great video loved it.
Ответить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?
ОтветитьDayumm, lmfao this was way better than creating an if statement for each object
ОтветитьThanks man, helped out a LOT with my game!
Ответить