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 天前
linux后台java、postSQL部署命令
java·linux·运维
月落归舟1 天前
MyBatis缓存机制
java·缓存·mybatis
huipeng9261 天前
企业级微服务开发实战(一):项目启动与工程化设计
java·开发语言·spring boot·spring cloud·微服务·云原生·架构
爱吃土豆的马铃薯ㅤㅤㅤㅤㅤㅤㅤㅤㅤ1 天前
java实现excel导入、下载模板方法
java·开发语言·excel
段ヤシ.1 天前
回顾Java知识点,面试题汇总Day12(持续更新)
java·mybatis
java1234_小锋1 天前
Spring AI 2.0 开发Java Agent智能体 - MCP(模型上下文协议)
java·人工智能·spring·spring ai
seven97_top1 天前
两小时入门Sentinel
java·sentinel
叶小鸡1 天前
Java 篇-项目实战-AI 天机学堂(从 0 到 1)-day1
java·开发语言
bigbearxyz1 天前
Caused by: java.net.SocketException: Connection reset问题排查
java·keepalived·proxysql
500841 天前
昇腾 CANN 的五层架构,到底分了哪五层
java·人工智能·分布式·架构·ocr·wpf