❔ (Unity C#) Dont know how to implement the OnCollisionEnter function w/ this code
Im referencing a template code for interaction and I want the Debug.Log to appear if Im interacting with the object and collision is happening simultaneously.
If I do this below it works fine
I just dont know how to implement the collision, below is my best attempt. (No errors btw)
Im not sure if this will help but heres the code im referencing below
6 Replies
OnCollisionEnter()
is good, but it should not be a local function
It should be a class member
https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnCollisionEnter.htmlThat makes a little more sense to me, it felt wrong writing it like that. The problem is I don’t know how to implement it as a class member 💀
Like any normal method
It goes into the class, not into another method
Am tired so I’ll try that more tomorrow, I did have it as a separate class earlier just didn’t know how to reference it into interact() without getting an error. Sorry I’m newer to coding so I don’t know what all the terms mean, got a little confused w/ local function and class member
I have a better idea on how to follow through with the code though, thanks.
Interact()
is a class member of ObjPlace
OnCollisionEnter(Collision)
is a local function of Interact()
so to make it OnCollisionEnter(Collision)
a class member as well it has to be on the same level nesting/next to the Interact()
method, not within inWas this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.
Was this issue resolved? If so, run /close
- otherwise I will mark this as stale and this post will be archived until there is new activity.