
作用:通过键盘移动视角transform
键盘wasd — 移动相机
using System.Collections;using System.Collections.Generic;using UnityEngine;public class movement : MonoBehaviour{public float speed = 5;// Start is called before the first frame updatevoid Start(){}// Update is called once per framevoid Update(){float h = Input.GetAxis("Horizontal");float l = Input.GetAxis("Vertical");transform.Translate(new Vector3(h,l,0)*Time.deltaTime * speed);}}
using System.Collections;using System.Collections.Generic;using UnityEngine;public class movement : MonoBehaviour{public float speed = 5;//移动速度// Start is called before the first frame updatevoid Start(){}// Update is called once per framevoid Update(){float h = Input.GetAxis("Horizontal");//上下方向键w、sfloat l = Input.GetAxis("Vertical");//左右方向键a、dtransform.Translate(new Vector3(h,l,0)*Time.deltaTime * speed);//按时间、速度定义,(0,0,0)对应(x,y,z)轴}}
1.把脚本拉到要移动的物体