国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Unity3D基礎

2019-11-17 02:14:23
字體:
來源:轉載
供稿:網友

Unity3D基礎

鼠標事件:

OnMouseEnter():鼠標進入

OnMouseExit():鼠標移出

OnMouseDown():鼠標點擊

OnMouseUp():鼠標抬起

static GameObject Instantiate() 克隆

static void Destroy()

位置 、 材料 、碰撞 、渲染

地形、預制、照相機、碰撞

using UnityEngine;using System.Collections;public class shubiao : MonoBehaviour {    // Use this for initialization    void Start () {        }        // Update is called once per frame    void Update () {        }    //:鼠標進入    void   OnMouseEnter(){        gameObject.renderer.material.color = Color.black;    }            void    OnMouseExit(){        gameObject.renderer.material.color = Color.blue;    }//:鼠標移出                void    OnMouseDown(){        gameObject.renderer.material.color = Color.yellow;    }//:鼠標點擊                    void    OnMouseUp()        {        gameObject.renderer.material.color = Color.red;        GameObject.Destroy (gameObject);        }//:鼠標抬起}

GUI布局

using UnityEngine;using System.Collections;public class GIU : MonoBehaviour {    PRivate string str="張三";    private string str2="";    private bool  sex=false;    private string _userName;    // Use this for initialization    void Start () {        }        // Update is called once per frame    void Update () {        }    void OnGUI()    {        /*if (GUI.Button (new Rect (10, 10, 70, 20), "按鈕")) {                    print ("A")    ;                }        if (GUI.RepeatButton (new Rect (10, 100, 70, 20), "按鈕")) {                print ("B")        ;                }        str=GUI.TextArea (new Rect (10, 20, 100, 20), str);        str2=GUI.PassWordField (new Rect (10, 150, 200, 20), str2, '*');        sex=GUI.Toggle(new Rect(10,100,50,50),sex,"男" );//check*/        GuI.Label(new Rect(10,10,70,20),"用戶名");        _userName = GUI.TextArea (new Rect (100, 10, 200, 20), _userName);        _sex = GUI.Toggle (new Rect (10, 70, 50, 20), _sex, "男");        _sex=GUI.Toggle(new Rect(10,140,50,20),!_sex,"女");    }}

GUILayOut 布局

例一:      private string str3="測試用的字符串";  //全局變量   GUILayout.Button ("GUILayout按鈕");        if (GUILayout.Button (str3)) {            str3+=str3 ;                }        if (GUI.Button (new Rect (50, 100, 100, 100), str)) {            str3+=str3;                }    

 例二:  GUILayout.BeginHorizontal ();  //水平排列        GUILayout.Button ("我是GUILayoutButton");        GUILayout.Button ("我是GUILayoutButton");        GUILayout.Button ("我是GUILayoutButton");        GUILayout.Button ("我是GUILayoutButton");        GUILayout.EndHorizontal ();        GUILayout.BeginVertical ();  //縱向排列        GUILayout.Button ("我是GUILayoutButton");        GUILayout.Button ("我是GUILayoutButton");        GUILayout.Button ("我是GUILayoutButton");        GUILayout.Button ("我是GUILayoutButton");        GUILayout.EndVertical();         

移動w 鍵 A鍵 S鍵 D鍵 :

using UnityEngine;using System.Collections;public class fouth : MonoBehaviour {//右邊是 Z 軸,上邊是y軸,X軸看不見的狀態;    GameObject go;    // Use this for initialization    void Start () {        go=GameObject.Find("Cube3");        go.renderer.material.color = Color.red;    }        // Update is called once per frame    void Update () {        if (Input.GetKey (KeyCode.W)) {            go.transform.Translate(-5*Time.deltaTime,0,0,Space.Self);                }        if (Input.GetKey (KeyCode.S)) {            go.transform.Translate(5*Time.deltaTime,0,0,Space.Self);        }        if (Input.GetKey (KeyCode.A)) {            go.transform.Translate(0,0,-5*Time.deltaTime,Space.Self);        }        if (Input.GetKey (KeyCode.D)) {            go.transform.Translate(0,0,5*Time.deltaTime,Space.Self);        }    }}

旋轉:

using UnityEngine;using System.Collections;public class NewBehaviourScript : MonoBehaviour {    // Use this for initialization    void Start () {        }        // Update is called once per frame    void Update () {//旋轉        gameObject.transform.Rotate (0, 15 * Time.deltaTime, 0, Space.Self);    }}

碰撞:

void OnCollisionEnter(Collision co)    {        co.gameObject.renderer.material.color = Color.blue;    }

預制(克隆):

void Update () {        if (Input.GetKeyUp (KeyCode.Space)) {            GameObject.Instantiate(go,gameObject.transform.position,gameObject.transform.rotation);                }    }
void Update () {        if (Input.GetKey (KeyCode.LeftShift)) {                        if (Input.GetKey (KeyCode.LeftShift)) {                                gameObject.animation.Play ("run");                gameObject.transform.transform(Vector3.forward*Time.deltaTime*6); //朝前移動 距離 速度                        } else {                                gameObject.animation.Play ("walk");                gameObject.transform.transform(Vector3.forward*Time.deltaTime*0); //朝前移動 距離 速度                        }                        }        else {            gameObject.animation.Play("stand");            gameObject.transform.transform(Vector3.forward*Time.deltaTime*3); //朝前移動 距離 速度                }         }

陰影烘焙:對燈設置 有陰影,對要烘焙的設置靜止,打開 windows 點 light烘焙 back ;

動畫剪輯:暫無

c#控制動畫:

application

切換場景

  if (Input.GetKeyDown (KeyCode.A)) {            Application.LoadLevel(0);                }

截屏

if (Input.GetKeyDown (KeyCode.Space)) {            Application.CaptureScreenshot(@"c:/1.png")                }

打開一個網址

Application.OpenURL("H");//打開一個網址

退出:

Application.Quit();//退出

左擊 游戲對象消失

        if(Input.GetMouseButtonDown(0)) //如果 按到 左擊        {            Ray ray=camera.main.ScreenPointToRay(Input.mousePosition);//拿到點擊的位置            RaycastHit hitInfo;            if(Physics.Raycast(ray,out hitInfo))//點擊到            {                Destroy (hitInfo.collider.gameObject);   //銷毀游戲對象            }        }


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 张家口市| 夏津县| 仁布县| 岫岩| 泰兴市| 周宁县| 石家庄市| 沙雅县| 滕州市| 博白县| 通化县| 文登市| 孝义市| 普洱| 南宁市| 普兰县| 庆元县| 阿鲁科尔沁旗| 英超| 襄樊市| 陇川县| 清丰县| 昌平区| 平舆县| 陇南市| 稷山县| 奈曼旗| 廉江市| 安康市| 和龙市| 依兰县| 台南县| 黎城县| 邢台市| 游戏| 通许县| 长宁县| 周至县| 忻州市| 和平区| 长治县|