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);


	}
}
相关推荐
笨拙的老猴子10 分钟前
Spring AI 实战教程(七):Agent 智能体 —— 用电商购物助手学透自主规划与工具执行
java·人工智能·spring
月落归舟14 分钟前
深入解析Java基础之基础
java·开发语言
折哥的程序人生 · 物流技术专研14 分钟前
《Java 100 天进阶之路》第20篇:Java初始化、构造器、对象创建的过程
java·开发语言·后端·面试
电魂泡哥21 分钟前
CMS垃圾回收
java·jvm·算法
Amctwd39 分钟前
【Python】从Excel中按行提取图片
java·python·excel
啃臭1 小时前
AOP和反射
java·spring boot
西凉的悲伤1 小时前
java 使用PNG图片隐写文件
java·图片隐写·png
有梦想的小何1 小时前
Cursor AI 编程实战(篇一):Prompt 与案例总结
java·linux·prompt·ai编程
河阿里1 小时前
SpringBoot:Spring Task定时任务完整使用教学
java·spring boot·spring
jiayong231 小时前
Tool Permission 与 Sandbox 的安全流水线:Agent 工具系统的工程边界
java·数据库·安全·agent