Unity 3D 第一更

Unity 3D 第一更

   这几年手机随着手机方面硬件的不断提升,手机上面的内存,Cpu,都不断的更新,以前的手机游戏已经不能满足手机发烧友的需求,希望在手机上面也能玩到像PC端的3D游戏,于是Unity 3D引擎就这样诞生了,Unity 3D不仅可以开发出手机方面的游戏,还可以对多个平台进行游戏开发,手机端 PC端 XBOX PSP PS4 andorid Iphone 等系统进行开发,所以今天我们就来说一说,Unity 3D 的游戏开发。
   首先说下Unity 3D 基础操作。
   Layout 布局 相对按钮
void OnGUI()
{
    //GUILayout.Width         布局宽度
        //GUILayout.Height        布局高度
        //GUILayout.MinHeight     最小布局高度
        //GUILayout.MinWidth      最小布局宽度
        //GUILayout.MaxHeight     最大布局高度
        //GUILayout.MaxWidth      最大布局宽度
        //GUILayout.ExpandHeight  设置布局整体高度
        //GUILayout.ExpandWidth   设置布局整体宽度
      // GUILayout.BeginArea(new Rect(100,100,Screen.width,Screen.height));
         GUILayout.Button("设置布局按钮宽度为300,高度为30",GUILayout.Height(30),GUILayout.Width(300));

        GUILayout.Button("设置最小布局按钮宽度为100,最小高度为20", GUILayout.MinWidth(100), GUILayout.MinHeight(20));
        GUILayout.Button("设置最大布局按钮宽度为400,最大高度为40", GUILayout.MinWidth(100),GUILayout.MaxWidth(400), GUILayout.MaxHeight(40));
        GUILayout.Button("设置宽度不等于最宽按钮", GUILayout.ExpandWidth(false));
        GUILayout.Button("设置宽度为最宽按钮", GUILayout.ExpandWidth(true));
        //GUILayout.EndArea();
}

Unity 对数字的随机

void Update () {
        print (Random.Range (0,1));
        print (Random.Range (0.0f,1.0f));
    }

Unity 实现图片帧动画的脚本

int noFrame = 0;
    int countFrame = 0;
    float time = 0;
    public string path;
    public int fps = 0;
    object [] all;

    // Use this for initialization
    void Start () {

        all=Resources.LoadAll(path);
        countFrame = all.Length;

    }

    // Update is called once per frame
    void Update () {
        if (all != null)
        {
            transform.GetComponent<Renderer>().material.mainTexture = (Texture)all[noFrame];
            time += Time.deltaTime;
            if (time >= 1.0 / fps)
            {
                noFrame++;
                time = 0;
            }
            if (noFrame >= countFrame)
            {
                noFrame = 0;
            } 

        }
    }
这里要注意的是在工程里面文件夹起名字的注意事项,文件夹的名称必须是Resources

Unity 中实现Windows窗口

 void OnGUI() 
    {
        //if(Input.GetMouseButton())
        GUI.Window(0,new Rect(0,0,100,100),mywindow,"是否接收任务");
    }

    void mywindow(int winid)
    {
        GUI.Label(new Rect(13,30,100,100),"撒大大");

    }
    // Update is called once per frame
    void Update () {
        print("12312313");
    }

Unity 通过按钮读取图片

    // Use this for initialization
    void Start () {

    }
    Texture simple;
    Object [] All;
    void OnGUI() 
    {
        if(GUILayout.Button("读取一张图片"))
        {
            simple = (Texture)Resources.Load("back");
        }
        if (GUILayout.Button("读取一张图片"))
        {
            All = Resources.LoadAll("windmill");
        }
        if(simple!=null)
        {
            GUI.DrawTexture(new Rect(0,0,Screen.width,Screen.height),simple, ScaleMode.StretchToFill,false,0);
        }
        if (All!=null)
        {
            for (int i =0;i<All.Length ;i++ )
            {
                GUI.DrawTexture(new Rect(i*64, 0, 64,64), (Texture)All[i], ScaleMode.StretchToFill, true, 0);
            }
        }
    }

    // Update is called once per frame
    void Update () {

    }

Unity 插值角度和固定角度

void OnGUI()
    {
        if(GUILayout.Button ("旋转固定角度"))
        {
            gameObject.transform.rotation = Quaternion.Euler (0,50,0);


        }

        if(GUILayout.Button ("旋转插值角度"))
        {
            rotate=true;
        }

    }
    bool rotate=false;
    // Update is called once per frame
    void Update () {
        if(rotate)
        {
            gameObject.transform.rotation = Quaternion.Slerp (gameObject.transform.rotation,Quaternion.Euler (0,50,0),Time.fixedDeltaTime);         

        }
    }

Unity 窗口添加文字

 int textureWidth;
    int textureHeight;
    int ScreenWidth;
    int ScreenHeight;
    public Texture texture;
    string str;
    // Use this for initialization
    void Start () {
        textureWidth=texture.width;
        textureHeight = texture.height;
        ScreenWidth=Screen.width;

        ScreenHeight=Screen.height;
        str = "第一个Untiy项目";
    }

    void OnGUI() 
    {
        GUI.Label(new Rect(10,10,330,20), str);
        GUI.Label(new Rect(10, 30, 330, 120), "当前屏幕宽"+ScreenWidth);
        GUI.Label(new Rect(10, 50, 330, 20), "当前屏幕高" + ScreenHeight);
        GUI.Label(new Rect(10, 70, textureWidth, textureHeight), texture);
    }

    // Update is called once per frame
    void Update () {

    }

在窗口中添加各种按钮

 public Texture2D buttonTexture;
    string strMes;
    int frameCount;
    // Use this for initialization
    void Start () {
        strMes = "请您点击按钮";
    }
    // Update is called once per frame
    void OnGUI() 
    {

        if(GUI.Button(new Rect(10,50,buttonTexture.width,buttonTexture.height),buttonTexture))
        {
            strMes = "您点击了图片按钮";
        }
        GUI.color = Color.green;
        GUI.backgroundColor = Color.red;
        if (GUI.Button(new Rect(10, 200, 100,50), "文字按钮"))
        {
            strMes = "您点击了文字按钮";
        }
        if(GUI.RepeatButton(new Rect(40,10,120,30),"按钮按下中"))
        {
            strMes = "您按下该按钮已经按下的时间为:"+frameCount+"";
            frameCount++;
        }
        GUI.Label(new Rect(10, 10, Screen.width, 30), strMes);
    }

    // Update is called once per frame
    void Update () {

    }

Unity 窗口分割区域

 public Texture t1;
    public Texture t2;
    // Use this for initialization
    void Start()
    {

    }
    void OnGUI()
    {
        GUI.BeginGroup(new Rect(0, 0, 600, 600));
        GUI.Label(new Rect(300, 390, 100, 100), "啦啦啦啦");
        GUI.Label(new Rect(0,0,50,20),"1231asdasdas");
        GUI.DrawTexture(new Rect(100,100,150,150),t1);
        GUI.EndGroup();

        GUI.BeginGroup(new Rect(30,30, 600, 600));
        GUI.Label(new Rect(300, 390, 100, 100), "啦啦啦啦");
        GUI.Label(new Rect(0, 0, 50, 20), "1231asdasdas");
        GUI.DrawTexture(new Rect(100, 100, 150, 150), t1);
        GUI.EndGroup();
    }
    // Update is called once per frame
    void Update()
    {
       //gameObject.GetComponent<Light>().enabled=;

        //GameObject.fin
        //提示:射线
        //将森林里所有的火把的光默认关掉,
        //先播放背景音乐(恐怖点的),点击NPC以后,,NPC说话,出现接收任务框,接收任务了以后所有火把点亮
        //任务的内容是 拾取10个上古神物,神物的旁边都会有魔法照射  ,有火把的地方就有神物的可能性

    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值