diff --git a/posts/studycase1.md b/posts/studycase1.md
index cff38a3..2380de8 100644
--- a/posts/studycase1.md
+++ b/posts/studycase1.md
@@ -59,7 +59,9 @@ head:
- 安装 `Input System` 与 `Cinemachine`
-
+
+
+> 提示:安装 Input System 后,Unity 会提示重启并切换至新输入系统,务必确认。
- 导入示例
@@ -73,11 +75,21 @@ head:
-> 提示:安装 Input System 后,Unity 会提示重启并切换至新输入系统,务必确认。
+- 模型目前是紫色的,材质需要进行修改,搜索所有材质
+
+
+
+- 依次点击,切换到URP
+
+
+
+- 点击确定,等待完成
+
+
## 5.勇者行迹录-章节任务
### 添加虚拟相机根节点
-- 为相机添加 `CinemachineBrain`作为根节点以便统一控制
+- 在主相机`Main Camera`上添加 `CinemachineBrain`作为根节点以便统一控制
@@ -97,18 +109,23 @@ head:
### 创建 InputActions
-- 创建`Resources`文件夹,右键 `Create > Input Actions`,,命名为 `PlayerInputActions`
+- 创建`Resources`文件夹,右键 `Create > Input Actions`,命名为 `PlayerInputActions`
-
+
+
- 创建 `Player` Action Map,添加 `Move`(Vector2)与 `Jump`(Button)
-- Move 绑定 `WASD` ;Jump 绑定 `space`
+- Move 绑定 `WASD`
-
+
+
+- Jump 绑定 `space`
+
+
### 编写脚本`ThirdCharacterController.cs`
- 在 `Assets\Scripts\StudyCase1` 下创建脚本 `ThirdCharacterController`
diff --git a/posts/studycase2.md b/posts/studycase2.md
index 082e91e..db62e6a 100644
--- a/posts/studycase2.md
+++ b/posts/studycase2.md
@@ -142,7 +142,7 @@ namespace StudyCase2
model = transform.Find("Model");
animator = model.GetComponentInChildren();
vCam = transform.Find("Virtual Camera").GetComponent();
- inputAction = Resources.Load("Player");
+ inputAction = Resources.Load("PlayerInputActions");
inputAction.FindAction("Move").started += OnMove;
inputAction.FindAction("Move").performed += OnMove;
inputAction.FindAction("Move").canceled += OnMove;
@@ -173,7 +173,7 @@ namespace StudyCase2
}
public void OnJump(InputAction.CallbackContext context)
{
- if (context.performed && characterController.isGrounded)
+ if (characterController.isGrounded)
{
moveDir.y = jumpSpeed;
}
@@ -191,7 +191,7 @@ private void Awake()
model = transform.Find("Model");
animator = model.GetComponentInChildren();
vCam = transform.Find("Virtual Camera").GetComponent();
- inputAction = Resources.Load("Player");
+ inputAction = Resources.Load("PlayerInputActions");
inputAction.FindAction("Move").started += OnMove;
inputAction.FindAction("Move").performed += OnMove;
inputAction.FindAction("Move").canceled += OnMove;
@@ -210,8 +210,10 @@ private void Awake()
## 6.异闻录-FAQ
+- **代码查找组件报错**:确认获取物体的名字和物体实际名字一致。
+- **代码加载InputActionAsset报错**:确认处于`Resources`文件夹下,名字和查找名字一致。
- **移动不播放动画**:确认动画控制器的参数名字和脚本中设置的一样。
- **动画只播放一遍**:检查是否勾选循环播放,在模型上看。
-- **动画状态切换有延迟**:确认动画控制器中连接线的HasExitTime是否勾选。
+- **动画状态切换有延迟**:确认动画控制器中连接线的`HasExitTime`是否勾选。
完成以上步骤,即可得到一个带动画的第三人称控制器。[项目地址](http://home.gtuantuan.online:8300/TuanTuan/StudyCase)
\ No newline at end of file
diff --git a/posts/studycase3.md b/posts/studycase3.md
index 3ce1e7d..0163b11 100644
--- a/posts/studycase3.md
+++ b/posts/studycase3.md
@@ -115,6 +115,10 @@ namespace StudyCase3
+- 创建Pick输入事件,绑定按键F
+
+
+
- 修改`Assets\Scripts\StudyCase3` 下脚本 `ThirdCharacterController.cs`
```csharp
using UnityEngine;
@@ -160,7 +164,7 @@ namespace StudyCase3
model = transform.Find("Model");
animator = model.GetComponentInChildren();
vCam = transform.Find("Virtual Camera").GetComponent();
- inputAction = Resources.Load("Player");
+ inputAction = Resources.Load("PlayerInputActions");
inputAction.FindAction("Move").started += OnMove;
inputAction.FindAction("Move").performed += OnMove;
inputAction.FindAction("Move").canceled += OnMove;
@@ -168,6 +172,12 @@ namespace StudyCase3
inputAction.FindAction("Pick").performed += OnPickUp;
inputAction.Enable();
itemRoot = transform.Find("ItemRoot");
+ if (lineRenderer == null)
+ {
+ lineRenderer = gameObject.AddComponent();
+ lineRenderer.material = new Material(Shader.Find("Universal Render Pipeline/2D/Sprite-Unlit-Default"));
+ lineRenderer.useWorldSpace = true;
+ }
}
private void Update()
{
@@ -214,7 +224,12 @@ namespace StudyCase3
}
void CheckRayHit()
{
- if (pickMode != PickMode.RayCast) return;
+ lineRenderer.enabled = useDrawRay;
+ if (pickMode != PickMode.RayCast)
+ {
+ useDrawRay = false;
+ return;
+ }
Ray ray = new Ray(model.position, model.forward);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, maxDistance, layerMask))
@@ -239,17 +254,6 @@ namespace StudyCase3
}
void DrawRay(Vector3 startPos, Vector3 endPos, Color color)
{
- if (lineRenderer == null)
- {
- lineRenderer = gameObject.AddComponent();
- lineRenderer.material = new Material(Shader.Find("Universal Render Pipeline/2D/Sprite-Unlit-Default"));
- lineRenderer.useWorldSpace = true;
- }
- if (!useDrawRay)
- {
- lineRenderer.enabled = false;
- return;
- }
lineRenderer.startColor = lineRenderer.endColor = color;
lineRenderer.startWidth = lineRenderer.endWidth = 0.1f;
lineRenderer.positionCount = 2;
diff --git a/public/image/studycase1/jump绑定space.png b/public/image/studycase1/jump绑定space.png
new file mode 100644
index 0000000..7ec74c8
Binary files /dev/null and b/public/image/studycase1/jump绑定space.png differ
diff --git a/public/image/studycase1/切换到URP.png b/public/image/studycase1/切换到URP.png
new file mode 100644
index 0000000..a1790bf
Binary files /dev/null and b/public/image/studycase1/切换到URP.png differ
diff --git a/public/image/studycase1/创建playerinputactions.png b/public/image/studycase1/创建playerinputactions.png
index 123ea10..9468d12 100644
Binary files a/public/image/studycase1/创建playerinputactions.png and b/public/image/studycase1/创建playerinputactions.png differ
diff --git a/public/image/studycase1/命名为PlayerInputActions.png b/public/image/studycase1/命名为PlayerInputActions.png
new file mode 100644
index 0000000..d4a7f85
Binary files /dev/null and b/public/image/studycase1/命名为PlayerInputActions.png differ
diff --git a/public/image/studycase1/搜索所有材质.png b/public/image/studycase1/搜索所有材质.png
new file mode 100644
index 0000000..759799c
Binary files /dev/null and b/public/image/studycase1/搜索所有材质.png differ
diff --git a/public/image/studycase1/点击确定.png b/public/image/studycase1/点击确定.png
new file mode 100644
index 0000000..d035074
Binary files /dev/null and b/public/image/studycase1/点击确定.png differ
diff --git a/public/image/studycase1/配置虚拟相机.png b/public/image/studycase1/配置虚拟相机.png
index bf46332..1fa5520 100644
Binary files a/public/image/studycase1/配置虚拟相机.png and b/public/image/studycase1/配置虚拟相机.png differ
diff --git a/public/image/studycase3/创建Pick输入事件,绑定F.png b/public/image/studycase3/创建Pick输入事件,绑定F.png
new file mode 100644
index 0000000..35cfbb2
Binary files /dev/null and b/public/image/studycase3/创建Pick输入事件,绑定F.png differ