苏州网站建设营销推广,建设一个机械公司网站多少钱,设计学类,四川林峰脉建设工程有限公司网站本文主要总结实现角色移动的解决方案。 1. 创建脚本#xff1a;PlayerController 2. 创建游戏角色Player#xff0c;在Player下挂载PlayerController脚本 3. 把Camera挂载到Player的子物体中#xff0c;调整视角#xff0c;以实现相机跟随效果 3. PlayerController脚本代码…本文主要总结实现角色移动的解决方案。 1. 创建脚本PlayerController 2. 创建游戏角色Player在Player下挂载PlayerController脚本 3. 把Camera挂载到Player的子物体中调整视角以实现相机跟随效果 3. PlayerController脚本代码如下
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class PlayerController : MonoBehaviour
{public float speed 5.0f;// Start is called before the first frame updatevoid Start(){Transform transform GetComponentTransform();}// Update is called once per framevoid Update(){ Move();}private void Move(){float horizontalInput Input.GetAxis(Horizontal);float verticalInput Input.GetAxis(Vertical);Vector3 moveingVec new Vector3(horizontalInput, 0f, verticalInput) * Time.deltaTime * speed;transform.Translate(moveingVec);}
}