- Home /
RayCast Collision between 2 game objects (of the same prefab)
I asked the same on the forum, can be found here: http://forum.unity3d.com/threads/123130-RayCast-Collision-between-2-game-objects-%28of-the-same-prefab%29
Right now I'm working on a game that checks several collisions at once, but all this is realised within one and the same script for one type of each game object.
So right now I have one script that checks collision between: - 1 PLAYER and 1 BOX
Basically I dragged 1 PLAYER and 1 BOX to the game world. I attached a script to the PLAYER that sends out RayCasts to check for collision with the collider of that BOX. Now when the RayCast of the PLAYER hits the Collider of the BOX, the BOX should move. All this works extremely well and I'm happy with the result.
Now the problem is, if I drag ANOTHER BOX to the game world and the RayCast of the PLAYER hits one of the Colliders of these TWO BOXES, they BOTH get moved at the same time to the same direction. This is quite logical, as the RayCast script on the PLAYER tells the BOX to move to a specific coordinate.
Now the question is, how can I make my RayCast check every box seperated from eachother? So no matter how many boxes I add to the game world, every box should have their OWN collision.
If someone can please give me a headsup where to begin looking, I am incredibly thankful!
Answer by KuPAfoo · Dec 07, 2013 at 04:31 AM
I just ran into this problem with allowing multiple clients to view ONE prefab's changes when TWO or more of the same prefab are instantiated.
I know your post is old, but i found it on a search engine looking for player to player collision detection.
Simply change your recipient's code from a "Public" function to a "Private" function.