zoukankan      html  css  js  c++  java
  • 关于Unity 获得和使用GetComponent<MeshFilter>().mesh时的心得

    原文地址:http://blog.sina.com.cn/s/blog_7d9405e50100s061.html

    今天在使用Unity3D的时候遇到了一个问题:_tesGameObject是在Project中的一个Prefab。

        public GameObject _testGameObject;
        void Awake()
        {
            Mesh mesh=_testGameObject.GetComponent<MeshFilter>().mesh;
            Debug.Log(mesh.bounds.size);
        }
    这样使用的时候会导致将Prefab的Mesh给去掉了。所以第一次使用的时候好使。如果再次执行的时候就会遇到Prefab中的Mesh为Null了。 不知道是Unity3D的一个Bug还是自己理解有误。反正感觉就是Prefab的一些属性不能直接读取,需要实例化之后才能正常读取
    最后:解决方法是:
     public GameObject _testGameObject;
      void Awake()
        {
            GameObject gameInstance = (GameObject)Instantiate(_testGameObject);
            gameInstance.transform.position = Vector3.zero;
            gameInstance.name = _testGameObject.name;
            Mesh mesh=gameInstance.GetComponent<MeshFilter>().mesh;
            Debug.Log(mesh.name);
            Debug.Log(mesh.bounds.size);
        }
  • 相关阅读:
    jquery 只能输入汉字
    实现鼠标移到某个对象,在旁边显示层。
    jquery 清空页面中radio选项
    oracle 删除表中重复的数据
    jQuery 获取屏幕高度、宽度
    jquery清空from表单中的所有数据
    oracle sql语句大全
    mysql sql语句大全
    Java精品书籍推荐
    小萌库
  • 原文地址:https://www.cnblogs.com/dragon2012/p/3791504.html
Copyright © 2011-2022 走看看