2D Toolkit Forum
2D Toolkit => Support => Topic started by: famadori on May 31, 2014, 02:47:23 am
-
CameraAnchor'm adding to my prefab, however it does not apply. How do I do that?
-
I don't understand how you've got this set up. Please post screenshots or a repro case.
-
I'm adding to my prefab tk2dCameraAnchor the script and dragging the camera to camera property, however when I close the unity or throw an build prefab loses Anchor. This prefab is added to the screen by script so do not know if this will be the right way to do.
-
Able to resolve the problem added anchors the main camera and adding to this GameObject anchora scripted. I created this class to help me. This is the correct path?
public enum enumPosition
{
LowerLeft,
MiddleCenter
}
public static class Extensions
{
/// <summary>
/// Adiciona objeto na posição da tk2dCameraAnchor especificada.
/// </summary>
/// <param name="gameObject">GameObject que será posicionado</param>
/// <param name="ePos">Posição onde ficará o gameobject</param>
/// <param name="newLocalPosition">Nova posição de deslocamento do objeto</param>
public static void AddCamera(this GameObject gameObject, enumPosition ePos, Vector2 newLocalPosition = new Vector2())
{
var cam = GameObject.Find("tk2dCamera").transform.FindChild(ePos.ToString());
gameObject = GameObject.Instantiate(gameObject, cam.transform.position, cam.transform.rotation) as GameObject;
gameObject.transform.parent = cam.transform;
if (newLocalPosition != default(Vector2))
{
gameObject.transform.localPosition = newLocalPosition;
}
}
}
-
The tk2danchor needs to be linked to a camera, either create a prefab with the camera, or link it up the way you have. It should also be a child of the camera when initialized.
-
I have to pre configure a prefab with a TK2CameraAnchor and add for instance? Or need to add the anchor after instantiating this way gameObject.transform.parent = cam.transform;
-
anchor.transform.parent = camera.transform;
anchor.AnchorCamera = camera;
-
Perfect. Thanks.