1. 程式人生 > >看向目標並且旋轉

看向目標並且旋轉

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/***
*    Title: "***"
*     主題:***
*    description:
*     功能:YYY
*    Data:2018
*    version(版本):
*    Modify recoder(修改記錄):
*/

public class LookAtTargetAndRound : MonoBehaviour {

	public Transform realLookAtTran;

	public Transform target;

	public Transform controllerGo;

	public Vector3 offsetEuler;
	public Vector3 OldEulerOfcontrollerGo;
	// Use this for initialization
	void Start () {
		offsetEuler=realLookAtTran.eulerAngles-controllerGo.eulerAngles;
		OldEulerOfcontrollerGo = controllerGo.eulerAngles;

	}
	
	// Update is called once per frame
	void Update () {

		//controllerGo.LookAt(target.position);
		if (Input.GetMouseButtonDown(1))
		{
			//this.Log("mousebuttonDown");

		}
		if (Input.GetMouseButton(1))
		{
			//this.Log("mousebutton");
			

		}if(Input.GetMouseButtonUp(1))
		{
			this.Log("mouseup");

		}

		realLookAtTran.LookAt(target.position);
		Vector3 tempEuler = realLookAtTran.eulerAngles;
		Vector3 targetEuler = tempEuler + offsetEuler;

		controllerGo.eulerAngles =new Vector3(OldEulerOfcontrollerGo.x, targetEuler.y,OldEulerOfcontrollerGo.z);

	}
}