- Home /
OnCollisonEnter refrence not working
I am trying to make a game where a rolling ball picks up items with rigidbodies as a proof of concept, however I keep getting the error message: "'transform' is not a member of 'object'". I use boo for scripting so that might be the problem. The code:
import UnityEngine
class ParentOnCollide (MonoBehaviour):
def Start ():
pass
def Update ():
pass
def OnCollisonEnter(NewCollide):
NewCollide.transform.parent = gameObject.transform.parent
def OnCollisonExit(NewCollide):
NewCollide.transform.parent = gameObject.transform.parent.transform.parent
Change
NewCollide.transform.parent
to
NewCollide.gameObject.transform.parent
Its is giving the error because a transform is a member of gameObject ,not the object.
GameObject is subclass/derived of Object.
"'gameObject' is not a member of 'object'"
try def OnCollisonEnter(NewCollide col): col.gameObject.transform.parent = gameObject.transform.parent
Answer by meat5000 · May 17, 2014 at 10:55 AM
col in Noob_Vulcans comment should be replaced by the name of your Collision as defined in the function argument.
But in your code you have missed the Collision definition and the return type
def OnCollisonEnter(NewCollide as Collision) as void:
I have noticed in JS that, even though you should be able to access the collision transform directly, sometimes it makes you go through the gameObject, just as Noob_Vulcan stated.
Look at this page:
Select Boo from the "Scripting Reference using" dropdown box.
It's not returning any compiler errors now, but it doesn't appear to detect that it is colliding with any of the blocks and just rolls over them. I added a debug print on the functions and it doesn't return anything, so it must not be detecting collisions, any guesses as to why?
Your answer
Follow this Question
Related Questions
Why is my object tilting when moving? 2 Answers
AddForceAtPosition to Parent's rigidbody...C# 0 Answers
Child rigidbody clipping through walls. 2 Answers
Should i be able to add gameobjects as children to a parent with a rigidbody? 1 Answer
Apply force to a rigidbody based on the rotation of a child object. 0 Answers