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; } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。