Hello Guest

Author Topic: Instantiate tk2dSprite loses tag  (Read 3736 times)

mygamingproject

  • Newbie
  • *
  • Posts: 37
    • View Profile
Instantiate tk2dSprite loses tag
« 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:

Code: [Select]
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

Code: [Select]
laser.tag = "Laser";

But no joy, any ideas?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Instantiate tk2dSprite loses tag
« Reply #1 on: August 16, 2014, 12:01:22 pm »
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...

LaserDinosaur

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: Instantiate tk2dSprite loses tag
« Reply #2 on: August 19, 2014, 06:59:25 pm »
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?