- 这里是源码
- 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 镜头跟随鼠标旋转移动
最新推荐文章于 2024-07-29 21:59:26 发布