Unity(第十七部)Unity自带的角色控制器

组件Character Controller 中文角色控制器

csharp 复制代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class player : MonoBehaviour
{
	private CharacterController player;
	void Start()
	{

		player= GetComponent<CharacterController>();
	}


	void Update()
	{

		//水平轴
		float horizontal = Input.GetAxis("Horizontal");
		//垂直轴
		float vertical = Input.GetAxis("Vertical");
		//创建成一个方向向量
		Vector3 dir = new Vector3(horizontal, 0, vertical);
		//打印向量
		//Debug.DrawRay(transform.position, dir, Color.red); 
		//朝向该方向移动
		//无重力影响
		player.Move(dir);
		//有重力影响
		//	player.SimpleMove(dir);


	}
}
相关推荐
文丑颜不良啊1 小时前
LeetCode3401~3420题目解析
java·leetcode
文丑颜不良啊2 小时前
LeetCode3421~3440题目解析
java·leetcode
code2cat3 小时前
【随笔】Java客户端选了HTTP/3,怎样知道请求实际走了哪个版本
java·开发语言·http
码云社区4 小时前
Java在线租房系统源码:VR看房素材、房源图片与内容维护方案
java·vue.js·vr·租房小程序·在线租房·看房租房
码云社区5 小时前
Spring Boot智慧物业系统源码:合同到期提醒、续签资料与资产协作
java·spring boot·后端·物业管理·物业系统·智慧物业
AI开源软件5 小时前
Vue3+SpringBoot3 业务配置统一管理:接管、保存与回退怎样保留有效值
java·前端·vue.js·spring boot·vue·ruoyi office
陈如水5 小时前
Spring AI Alibaba 在多 Agent 场景下的实践
java·人工智能·spring
吃我一窝jio6 小时前
Docker+Jenkins+K8s全流程部署
java·开发语言·笔记·python
Resean02239 小时前
Spring 源码分析(六)循环依赖与三级缓存
java·spring·缓存
在爪洼山玩泥巴9 小时前
fastjson2 JSONPath 取不存在路径,为什么会抛 “not support”?
java·开发语言·jsonpath·fastjson