![alt text][1]
[1]: /storage/temp/71992-nn12.png
I'm trying in put a 3D Object to 2D world.
Like left figure, I written a code that rotating 'Pillar' to tracking 'LookAt' in 2D camera mode.
[ExecuteInEditMode]
public class test : MonoBehaviour
{
public Transform RotRoot = null;
public Transform LookAt = null;
void Update()
{
Vector2 pillarPos = new Vector2(this.transform.localPosition.x, this.transform.localPosition.y);
Vector2 lookAtPos = new Vector2(LookAt.localPosition.x, LookAt.localPosition.y);
Vector2 dir = lookAtPos - pillarPos;
float angle = Vector2.Angle(dir, Vector2.down);
RotRoot.localEulerAngles = new Vector3(0.0f, angle, 0.0f);
Debug.DrawLine(this.transform.position, LookAt.position, Color.red);
}
}
But, when i rotate a 'Pillar' to X axis, like right above figure, a problem has raised.
I want to parallel the direction of 'Pillar' and 'Pillar-LookAt' connection line, like right below picture.
help me.
↧