unity练习笔记

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class demo3 : MonoBehaviour
{
    public GameObject Cube;
    public GameObject Prefab;
    float time = 0;
    float timer = 0;
    AsyncOperation operation;
    // Start is called before the first frame update
    /// <summary>
    /// 
    /// </summary>
    void Start()
    {
        //Debug.Log(gameObject.name);
        //Debug.Log(Cube.name);
        //Debug.Log(Cube.activeInHierarchy);
        //Debug.Log(Cube.activeSelf);

        //从当前物体自身获取组件
        //BoxCollider bc = GetComponent<BoxCollider>();

        //获取父物体身上获取某个组件
        //GetComponentInParent<Transform>();

        //获取子物体身上的某个组件
        //Transform childts = GetComponentInChildren<Transform>(bc);
        //Debug.Log(childts.position);

        //gameObject.AddComponent<AudioSource>();
        //Cube.AddComponent<AudioSource>();

        //查找物体
        // GameObject obj =  GameObject.Find("Test");
        //Debug.Log(obj.name);

        //实例化预制体
        //for (int i = 0; i < 100; i++)
        //{
        //    Instantiate(Prefab, new Vector3(i * 0.5f, i * 0.1f, 0), Quaternion.identity);
        //}

        //游戏开始到现在所花的时间
        //Debug.Log(Time.deltaTime);

        //时间缩放值
        //Debug.Log(Time.timeScale);

        //固定时间间隔
        //Debug.Log(Time.fixedDeltaTime);

        //游戏数据文件夹路径(只读,加密)
        //Debug.Log(Application.dataPath);

        //持久化文件夹路径 (可写)       
        //Debug.Log(Application.persistentDataPath);

        //游戏数据文件夹路径(只读,不加密)
        //Debug.Log(Application.streamingAssetsPath);

        //临时文件夹
        //Debug.Log(Application.temporaryCachePath);

        //后台运行
        //Debug.Log(Application.runInBackground);

        //打开一个网址
        //Application.OpenURL("https://fanyi.baidu.com/#en/zh/Application");

        //退出游戏
        //Application.Quit();

        //用场景索引切换
        //SceneManager.LoadScene("MyScene");

        //用场景名称切换
        //SceneManager.LoadScene(1);

        //获取当前场景
        //Scene curr = SceneManager.GetActiveScene();
        //Debug.Log("场景名称" + curr.name);
        //Debug.Log("获取当前场景下所有物体数量" + curr.GetRootGameObjects().Length);
        //Debug.Log("是否加载" + curr.isLoaded);
        //Debug.Log("当前场景路径" + curr.path);
        //Debug.Log("场景索引" + curr.buildIndex);

        //创建场景
        //Scene NewScene = SceneManager.CreateScene("NewScene");

        //场景数量
        //Debug.Log(SceneManager.sceneCount);

        //卸载场景
        //SceneManager.UnloadSceneAsync(NewScene);
        //SceneManager.UnloadSceneAsync("NewScene");

        //场景加载模式
        //SceneManager.LoadScene("MyScene",LoadSceneMode.Single); //替换
        //SceneManager.LoadScene("MyScene",LoadSceneMode.Additive); //添加

        //异步加载场景
        //StartCoroutine(loadScene());

        /*

        //获取位置
        Debug.Log(transform.position); //世界坐标
        Debug.Log(transform.localPosition); //本地坐标

        //获取旋转
        Debug.Log(transform.rotation);
        Debug.Log(transform.localRotation);
        Debug.Log(transform.eulerAngles);
        Debug.Log(transform.localEulerAngles);

        //获取向量
        Debug.Log(transform.forward);
        Debug.Log(transform.right);
        Debug.Log(transform.up);

        */

        //获取父物体
        //GameObject parents = transform.parent.gameObject;
        //Debug.Log(parents.name);

        //获取子物体个数
        //Debug.Log(transform.childCount);

        //接触与子物体的父子关系
        //transform.DetachChildren();

        //查找物体
        //Transform obj = transform.Find("child");
        //GameObject obj = GameObject.Find("child");
        //obj =  transform.GetChild(0);
        //Debug.Log(obj.IsChildOf(transform));

        //设置父物体
        //obj.SetParent(transform);

        //开启多点触摸
        //Input.multiTouchEnabled = true;
    }

    //异步加载场景方法
    IEnumerator loadScene()
    {
        operation = SceneManager.LoadSceneAsync(1);
        //自动加载场景
        operation.allowSceneActivation = false;
        yield return operation;
    }

    // Update is called once per frame
    void Update()
    {
        //time += Time.deltaTime;
        //if(time > 3)
        //{
        //    Debug.Log("时间大于3");
        //}

        //大于5秒自动加载场景
        //timer += Time.deltaTime;
        //if (timer > 5)
        //{
        //    operation.allowSceneActivation = true;
        //}
        //Debug.Log(operation.progress);

        //固定看向某个点
        //transform.LookAt(Vector3.zero);

        //围绕某个物体旋转
        //transform.Rotate(Vector3.up,5);
        //transform.Rotate(new Vector3(90, 0, 0), 5);
        //transform.Rotate(Vector3.up);

        //移动
        //transform.Translate(Vector3.forward*0.1f);



        //鼠标事件 0左键   1右键   2滚轮
        //if (Input.GetMouseButtonDown(2))
        //{
        //    Debug.Log("按下左键");
        //}

        //if (Input.GetMouseButton(2))
        //{
        //    Debug.Log("持续按下");
        //}

        //if (Input.GetMouseButtonUp(2))
        //{
        //    Debug.Log("抬起左键");
        //}


        //键盘事件
        //if (Input.GetKeyDown(KeyCode.A))
        //{
        //    Debug.Log("按下A键");
        //}

        //if (Input.GetKey(KeyCode.A))
        //{
        //    Debug.Log("持续按下A键");
        //}

        //if (Input.GetKeyUp(KeyCode.A))
        //{
        //    Debug.Log("抬起A键");
        //}

        //获取水平轴
        //float horizontal = Input.GetAxis("Horizontal");
        //float vertical = Input.GetAxis("Vertical");
        //Debug.Log(horizontal + "    " + vertical);

        //虚拟按键
        //if (Input.GetButtonDown("Jump"))
        //{
        //    Debug.Log("按下空格");
        //}

        //if (Input.GetButton("Jump"))
        //{
        //    Debug.Log("持续按下空格");
        //}

        //if (Input.GetButtonUp("Jump"))
        //{
        //    Debug.Log("抬起空格");
        //}

        //判断单点触摸
        if (Input.touchCount == 1)
        {
            //触摸对象
            Touch toc = Input.touches[0];

            //触摸位置
            Debug.Log(toc.position);

            //触摸对象
            Touch touch = Input.GetTouch(0);

            //触摸阶段
            switch (touch.phase)
            {
                case TouchPhase.Began:
                    break;
                case TouchPhase.Moved:
                    break;
                case TouchPhase.Stationary:
                    break;
                case TouchPhase.Ended:
                    break;
                case TouchPhase.Canceled:
                    break;
                default:
                    break;
            }
        }


        //多点触摸
        //if (Input.touchCount == 2)
        //{
        //   Touch toc1 = Input.GetTouch(0);
        //   Touch toc2 = Input.GetTouch(1);

        //    switch (toc1.phase)
        //    {
        //        case TouchPhase.Began:
        //            break;
        //        case TouchPhase.Moved:
        //            break;
        //        case TouchPhase.Stationary:
        //            break;
        //        case TouchPhase.Ended:
        //            break;
        //        case TouchPhase.Canceled:
        //            break;
        //    }


        //    switch (toc2.phase)
        //    {
        //        case TouchPhase.Began:
        //            break;
        //        case TouchPhase.Moved:
        //            break;
        //        case TouchPhase.Stationary:
        //            break;
        //        case TouchPhase.Ended:
        //            break;
        //        case TouchPhase.Canceled:
        //            break;
        //    }
        //}



    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值