Problem with Quaternion.Euler() when rotating object

Hello,

I am trying to rotate a game object and I am using Quaternion.Euler to work out the rotation angle. However, I cannot get my code to work correctly. I don’t understand why, the Unity documentation for the Euler() function is simple enough.

For example: I rotate my game object to the right by 90 degrees. From this rotation I cannot rotate the game object up/down.

I have included the below code, just attach it to a game object and run. I use the new rotation to calculate a world coordinate for the game object to look at.

Please assist.

using UnityEngine;
using System.Collections;

public class Rotate : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		Vector3 rot = Vector3.zero;
		
		if (Input.GetKeyUp(KeyCode.DownArrow)) rot.x = -45;
		else if (Input.GetKeyUp(KeyCode.UpArrow)) rot.x = 45;
		else if (Input.GetKeyUp(KeyCode.LeftArrow)) rot.y = -45;
		else if (Input.GetKeyUp(KeyCode.RightArrow)) rot.y = 45;
		
		if (rot != Vector3.zero) {
			Vector3 eulerAngles = Quaternion.Euler(rot) * -transform.forward;
	  		Vector3	lookToPosition = transform.position - eulerAngles * 100000;		

			transform.LookAt(lookToPosition);
		}
	}
}

Obviously something’s going wrong, there, but I’m afraid I’m not quite clever enough to spot it, just now.

Depending on what exactly you’re trying to do, either of these might work:

//identify resulting point
//you could call transform.LookAt() with this
//or Debug.DrawLine(), etc etc
transform.TransformPoint(Quaternion.Euler(rot) * Vector3.forward);

//rotate object
//can specify self-space or world-space to get diff behavior
transform.Rotate(rot);

See this post:
http://forum.unity3d.com/threads/136444-Calculate-a-new-position-based-using-an-angle-and-distance

Im trying to convert Euler angles to quaternions, but no matter what it sets the rotation to 135, -90, -225 (not what Im aiming for). I have no idea how to use quaternions, so Im stumped. it might be a bug.