1:从当前物体发射一条射线
RaycastHit hit;
Vector3 v = this.transform.TransformDirection(Vector3.forward);
if (Physics.Raycast(this.transform.position,v,out hit))
{
print(hit.collider.name);
}
2:Ugui检测穿透
if (EventSystem.current.IsPointerOverGameObject())
return;
3:更换材质球
public Material[] _MyMaterial;
this.GetComponent<MeshRenderer>().materials = _MyMaterial;
4:利用UGUI + Android(ui检测)
将此方法添加到脚本中
bool CheckGuiRaycastObjects()
{
PointerEventData eventData = new PointerEventData(e);
eventData.pressPosition = Input.mousePosition;
eventData.position = Input.mousePosition;
List<RaycastResult> list = new List<RaycastResult>();
G.Raycast(eventData, list);
//Debug.Log(list.Count);
return list.Count > 0;
}
在发射线的上面添加if (CheckGuiRaycastObjects()) return;就好;
5:物体旋转从当前角度旋转到指定的角度后停止旋转
var qua2 = Quaternion.Euler(0, -66f, 0);
Modl.rotation = Quaternion.Slerp(Modl.rotation, qua2, Time.deltaTime * 1);
6:定义区域块
#region
#endregion
7:unity3d设置全屏显示(Pc)
//按ESC退出全屏
if(Input.GetKey(KeyCode.Escape)){
Scerrn.fullScreen =false; //退出全屏
}
if(Input.GetKey(KeyCode.A)){
//获取设置当前屏幕分辩率
- Resolution[] resolutions = Screen.resolutions;
- //设置当前分辨率
- Screen.SetResolution(resolutions[resolutions.Length - 1].width, resolutions[resolutions.Length - 1].height, true);
- Screen.fullScreen = true; //设置成全屏,
}
AOT Compatibility Options 填上字符串:nrgctx-trampolines=8096,nimt-trampolines=8096,ntrampolines=4048 参考的这里,如果你的APP有不知名的闪退情况的话,请加上这条属性