2D Toolkit Forum
2D Toolkit => Support => Topic started by: mygamingproject on August 16, 2014, 10:11:33 am
-
I have a tk2dSprite (a laser) that I have create as a prefab. There are four lasers positioned in opposites corners of a rectangle firing in.
I used a Rigidbody2d to push with force and isTrigger to detect on collision with the player. This bit works well.
The problem is when they pass the player and the the lasers collide. I have removed the laser collision from the physics matrix yet still they collide.
So I tested the layer to see what was return and see the instantiated object (the laser) is marked as "Untagged" and not "Laser" as is in the prefab.
Here is my calling code:
GameObject laser = Instantiate(Resources.Load("Prefabs/Laser")) as GameObject;
laser.transform.position = turret.transform.position;
laser.transform.rotation = turret.transform.rotation;
laser.transform.Rotate(0, 0, tempAngle);
I have even tried adding the tag in again
laser.tag = "Laser";
But no joy, any ideas?
-
We don't touch the tags in any way, so this is probably due to unity screwing up something when instantiating the prefab if thats being changed... Also, tags are not used in the physics matrix - but rather its the layer property that relates to the matrix...
-
1) Does your laser prefab have any child nodes? If so, is your collider attached to the parent or the child node?
2) If you do a check for 'laser.transform.name', what is it called?