unity3d小常识

来源:互联网 发布:flash cc mac 编辑:程序博客网 时间:2024/05/16 11:04

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;  //设置成全屏,  

}

0 0
原创粉丝点击