|
Hello, I'm using the Orthello2d asset. Using C#, I've set up a delegate to handle collisions and am trying to print the name of the object colliding with the player, however receive the error: An object reference is required to access non-static member `UnityEngine.Collision.gameObject' I am not very experienced, so my guess is somewhere along the lines of "I need to make an instance or something of the Collision member first or 'declare' something..." I don't know.
(comments are locked)
|
|
Apart from learning, do you have a good reason for not using the collision detection of the engine? It's doing it all for you. But if you want to learn then I understand. Now your problem might be that you declare a OTObject sprite but the GetComponent returns a OTSprite. So it probably returns null. The Orthello framework has tools for collisions between its object, but according to the user manual, it uses Unity's collider system. So I'm pretty sure this is the simplest way to handle the collisions. If I remove the line that tries to receive the colliding object's name, the collision is detected just fine. The problem is trying to find the name of the collider.
Jul 17 '12 at 07:11 PM
Ishkur
Try with this: Notice that you pass a OTObject owner but use Collision. What is this? (I am not familiar with the Orthello framework so my guess could be wrong). Still, you should consider what I mentioned in the answer since you tried to pass a OTSprite to a OTObject (then again Orthello might allow that).
Jul 17 '12 at 07:19 PM
fafase
Hm... that just returns the name of the player, not the object colliding with it. That's a funny what you pointed out, though. I hadn't noticed that I had declared an OTObject but then passed OTSprite from then on. It works in Orthello, but I guess it is developing a bad habit in me.
Jul 17 '12 at 07:37 PM
Ishkur
I'm sorry for wasting your time. What I had needed was owner.collisionObject.name; with collisionObject being a method of Orthello's OTObject, so nobody would have been able to answer the question without knowledge of the package. I would still like to know how I would get the name of the colliding GameObject using Unity's script, however, as I'm pretty convinced my original code should have worked without that non-static member error.
Jul 17 '12 at 07:42 PM
Ishkur
Well, I did tell you to use: I was close!! Now in UnityScript, it goes: You pass the other object, this one is colliding with. You can access all types of variables and functions with the reference other. In my exemple, I check the tag of the object to be anything and perform an action if it is, colliding with an object tagged "Something" will not do.
Jul 17 '12 at 08:29 PM
fafase
(comments are locked)
|
|
To get the Colliding object use OTObject owner.collisionObject To get the Collision use OTObject owner.collision
(comments are locked)
|
|
If you want to access a non-static variable or function, you need an object with the respective script in the scene. Having the script in the Project Folder alone is not enough. Only static functions/variables can be accessed without having them in the scene. Yes, this script is in the scene and attached to the player whose collisions are being checked against other objects.
Jul 17 '12 at 07:11 PM
Ishkur
(comments are locked)
|
