Unit1

Position 三维坐标
Rotation 旋转角度
Scale 不同方向上的缩放
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}Start()在游戏开始时执行一次
Update()会在每一帧进行执行一次
Transform.Translate()
在Unity中,Transform.Translate方法用于在游戏对象的局部坐标系中进行平移操作。这意味着它将游戏对象沿着其自身的轴进行移动,而不是世界坐标轴。这在实现物体移动、相机跟随、用户交互等方面非常有用
Vector3.forward/up/down/forward/back/left/right
使用Vector3进行方向改变十分方便
Mesh Collider 网格碰撞器
Rigid body 刚体


利用GameObject来关联其他
具体代码:CameraFollow
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollow : MonoBehaviour
{
public GameObject player;
private Vector3 offset = new Vector3(0, 7, -15);
// Start is called before the first frame update
void Start()
{
//offset = transform.position - player.transform.position;
}
// Update is called once per frame
//void Update()
//{
// transform.position = player.transform.position+offset;
//}
void LateUpdate()
{
transform.position = player.transform.position + offset;
}
}PlayerController
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float speed;
public float turnspeed;//旋转速度
public float verticalInput;//垂直输入(前后)
public float horizontalInput;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//transform.Translate(0, 0, 1);
verticalInput = Input.GetAxis("Vertical");//取值为-1,0,1
//没有按住,0
//按住w,1
//按住s,-1
horizontalInput = Input.GetAxis("Horizontal");
transform.Translate(Vector3.forward * Time.deltaTime * speed * verticalInput);//位移 方向*时间修正*速度
transform.Rotate(Vector3.up, horizontalInput * turnspeed * Time.deltaTime);//旋转 三维坐标轴,旋转角度
//0,1,0
}
}Unit2
Input.GetAxis方法和Input.GetAxisRaw方法
前者可以获得-1到1之间的所有值,但后者只会获得-1,0,1
预制件得先完成所有操作:碰撞盒,刚体,碰撞体设置再拖入prefab文件夹
两个物品一定都要有碰撞器且其中之一要有刚体才会碰撞