Camera look position is always fixed.. need help.

I have a camera script that i’ve written for my RPG. The camera allows the player to click the right mouse button and look around. This feature works great. When you let go of the button the camera gently floats behind the player again. The problem is, when you click the right mouse button again, the camera always starts at a fixed rotation (0,0,0) no matter which way the character is turned. I need that rotation to always be looking at the player… Any help I can get would be great.

here’s the script C#:

using UnityEngine;
using System.Collections;

public class RPGCamera : MonoBehaviour {
	
	public Transform target;
	public string playerTagName = "Player";
	
	public float walkDistance;
	public float runDistance;
	public float height;
	public float xSpeed = 250.0f;
	public float ySpeed = 120.0f;
	public float heightDamping = 2.0f;
	public float rotationDamping = 2.0f;
	
	private Transform _myTransform;
	private float _x;
	private float _y;
	private bool _camButtonDown = false;
	
	
	
	void Awake(){
		_myTransform = transform;
	}
	// Use this for initialization
	void Start () {
		if(target == null)
			Debug.LogWarning("We do not have a target");
		else{
			CameraSetup();
	
		}
		
		
		
	}
	void Update (){
		if(Input.GetMouseButtonDown(1)){	//Use the Input Manager to make this user selectable.
			_camButtonDown = true;
		}
		if(Input.GetMouseButtonUp(1)){
			_camButtonDown = false;	
		}
		if(Input.GetAxis("Mouse ScrollWheel") < 0){
			walkDistance += 1;	
		}
		if(Input.GetAxis("Mouse ScrollWheel") > 0){
			walkDistance -= 1;	
		}
		if(walkDistance > 10){
			walkDistance = 10;	
		}
		if(walkDistance < 5)
			walkDistance = 5;
		}
	
	void LateUpdate(){
		if(target != null){
			if(_camButtonDown){	
			_x += Input.GetAxis("Mouse X") * xSpeed * 0.02f;
       		_y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;
 		
// 			_y = ClampAngle(_y, yMinLimit, yMaxLimit);
 		       
       		 Quaternion rotation = Quaternion.Euler(_y, _x, 0);
       		 Vector3 position = rotation * new Vector3(0.0f, 0.0f, -walkDistance) + target.position;
        
       		 _myTransform.rotation = rotation;
       		 _myTransform.position = position;	
			}
		else{
//			_myTransform.position = new Vector3(target.position.x, target.position.y + height, target.position.z - walkDistance);
//			_myTransform.LookAt(target);
			_x = 0;
			_y = 0;
				
			// Calculate the current rotation angles
				float wantedRotationAngle = target.eulerAngles.y;
				float wantedHeight = target.position.y + height;
					
				float currentRotationAngle = _myTransform.eulerAngles.y;
				float currentHeight = _myTransform.position.y;
				
				// Damp the rotation around the y-axis
				currentRotationAngle = Mathf.LerpAngle(currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);
			
				// Damp the height
				currentHeight = Mathf.Lerp(currentHeight, wantedHeight, heightDamping * Time.deltaTime);
			
				// Convert the angle into a rotation
				Quaternion currentRotation = Quaternion.Euler(0, currentRotationAngle, 0);
				
				// Set the position of the camera on the x-z plane to:
				// distance meters behind the target
				_myTransform.position = target.position;

			_myTransform.position -= currentRotation * Vector3.forward * walkDistance;
		
			// Set the height of the camera
			_myTransform.position = new Vector3(_myTransform.position.x, currentHeight, _myTransform.position.z);
			
			// Always look at the target
			_myTransform.LookAt (target);
		
	}
}
	else{
		GameObject go = GameObject.FindGameObjectWithTag(playerTagName);
		
		if(go == null)
			return;
		target = go.transform;
	}
	
	
			
}
public void CameraSetup(){
		_myTransform.position = new Vector3(target.position.x, target.position.y + height, target.position.z - walkDistance);
		_myTransform.LookAt(target);
}

}

You need to set _x and _y to current camera Euler angles when mouse is clicked.

Removed for spamming.

Please ban this guy.

Removed for spamming.

Please ban this guy.