1、主角移动
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour {
public float speed = 5f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0f);
transform.position += movement * speed * Time.deltaTime;
}
}
2、摄像机移动
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour
{
PlayerController player;
public bool follow = true;
// Use this for initialization
void Start()
{
player = FindObjectOfType<PlayerController>();
}
// Update is called once per frame
void LateUpdate()
{
if (player != null && follow)
transform.position = player.transform.position + new Vector3(0f, 0f, -10f);
}
}
3、C#语法基础
4、C#面向对象基础
5、MVC简介
MVC 是软件开发行业比较经典的设计模式, 是一种代码开发的思想和套路。将要实现的某个功能分成三个部分:
- V: View[视图层], 也就是界面, 主要负责和用户进行输入输出的交互;
- C: Controller[控制器层], 负责处理该功能的逻辑部分;
- M: Model[模型层], 主要对数据进行操作;
6、C#数据结构基础
7、刚体触发事件的监测与处理
- 触发器
将碰撞体组件属性面板上的“Is Trigger” 选项选中, 当前的游戏物体的碰撞体就变成了触发器。移动的刚体物体会穿透碰撞体勾选了“Is Trigger” 的物体。 - 触发事件
当一个用刚体控制的物体进入到另外一个物体的触发器范围内, 就是触发事件。触发用途: 不与目标物体发生直接的碰撞(接触), 而是只要进入目标物体的“触发范围” 就能执行某些特定操作。