Unity一些杂七杂八的笔记
简单Player移动
主摄像头放到Player下
加script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
CharacterController controller;
public float speed = 5;
void Start()
{
controller = GetComponent<CharacterController>();
}
void Update()
{
// movement
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = transform.right * x + transform.forward * z;
controller.Move(move * speed * Time.deltaTime);
}
}
NPC漫游
导入城市资源
给所有物体加Mesh Collider(否则后面检测人行道时
Physics.Raycast无法检测)给人行道设置layer为sidewalk,导航->对象->Navigation Static
给桌椅、房子等设置Navigation Static,Not Walkable
放一个胶囊当NPC,加组件Nav Mesh Agent
加script(ref:FULL 3D ENEMY AI in 6 MINUTES! || Unity Tutorial)
1 | using System.Collections; |
- 设置script引用