Rigidbody
(继承自Component,所以Component有的方法,Rigidbody都有)
- centerOfMass:取得重心
- Position:通过刚体组件设置物体的位置,控制物体的运动,瞬间的移动
- MovePosition:让整个运动看起来更加平滑,持续的移动
- Rotation:通过刚体组件设置物体的旋转,节约性能,一次改变
- MoveRotation:持续不断的旋转
- AddForce:模拟一个物理(力)的效果(如:推箱子)
测试代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class API15RigidbodyPosition : MonoBehaviour {
public Rigidbody playerRgd;
public Transform enemy;
public int force;
void Start () {
}
void Update () {
//playerRgd.position = playerRgd.transform.position + Vector3.forward * Time.deltaTime;
//playerRgd.MovePosition(playerRgd.transform.position + Vector3.forward * Time.deltaTime);
//if (Input.GetKey(KeyCode.Space))
//{
// Vector3 dir = enemy.position - playerRgd.position;
// dir.y = 0;
// Quaternion target = Quaternion.LookRotation(dir);
// playerRgd.MoveRotation(Quaternion.Slerp(playerRgd.rotation, target, Time.deltaTime));
//}
playerRgd.AddForce(Vector3.forward * force);
}
}
Camera
- main:查找Main Camera身上的Camera组件,tag必须为MainCamera(根据标签查找)
- ScreenPointToRay:射线检测碰撞(屏幕坐标转成射线)
- allCameras:取得场景当中所有的Camera,返回一个数组
- allCamerasCount:获取当前场景中Camera的数量
测试代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class API16Camera : Mono