unity3d 镜头随鼠标移动

using UnityEngine;
using System.Collections;

public class sheji : MonoBehaviour 
{
	public int speed = 5;
	
	public Transform newobject; 

	float axisX2 = 0;
	float axisY2 = 0;
	// Use this for initialization
	void Start () 
	{

	}

	// Update is called once per frame
	void Update () 
	{
		float x = Input.GetAxis("Horizontal") * Time.deltaTime * speed;
		float y = Input.GetAxis("Vertical") * Time.deltaTime * speed;

		transform.Translate(x,0,y);

		//transform.position = Vector3(0, 0, 0);
		//print (x);

		if(Input.GetButtonDown("Fire1"))
		{
			Transform n = Instantiate(newobject,transform.position,transform.rotation) as Transform;
			Vector3 fwd = transform.TransformDirection(Vector3.forward);
			n.rigidbody.AddForce(fwd*2800);
		}
		
		float axisX = Input.GetAxis("Mouse X");
		float axisY = Input.GetAxis("Mouse Y");

		axisX2 = axisX2 + axisX;
		axisY2 = axisY2 + axisY;

		//按镜头调整方向
		var rotation = Quaternion.Euler(-axisY2*speed, axisX2*speed, 0);

		transform.rotation = rotation;
	}
}

unity3d 镜头随鼠标移动,布布扣,bubuko.com

unity3d 镜头随鼠标移动

上一篇:Delphi-基础(运算符)


下一篇:C#中的时间戳