首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏宜达数字

    Unity基础(7)-GameObject

    01-Unity下的GameObject类 引擎下的GameObject菜单 引擎下的GameObject菜单 02-Unity下的GameObjcet类属性 Name 对象名,可以重复,无限数量 Tag 静态方法 静态方法 05-Unity下的GameObjcet类中的方法使用 静态方法 // 创建游戏对象 GameObject cube = GameObject.CreatePrimitive (PrimitiveType.Cube); // 动态创建实例化游戏对象(针对预制物,资源包内模型等) GameObject sp = GameObject.Instantiate Tag,找到Tag值为“Player”的物体 GameObject obj = GameObject.FindGameObjectWithTag("Player"); / /Debug.Log(obj.name); // 通过Tag,找到Tag值为“Player”的所有物体 GameObject[] objs = GameObject.FindGameObjectsWithTag

    2.4K20发布于 2020-06-02
  • 来自专栏叶子的开发者社区

    Unity3D之GameObject

    当涉及到游戏开发时,Unity3D的GameObject(游戏对象)是一种非常基本且重要的概念。GameObject代表了在游戏场景中显示、交互和操控的实体。 在代码中,你可以使用各种API来操作GameObject。例如,使用Instantiate方法可以在运行时动态创建GameObject的实例。 另外,Unity还提供了事件系统,用于监听和处理与GameObject相关的事件。例如,你可以编写代码来检测碰撞发生的事件,并触发相应的逻辑。 在Unity3D中,GameObject是由组件构成的。 Script(脚本)组件 作用:允许你附加自定义的脚本代码到GameObject上,实现特定的行为和逻辑。 使用方法:创建一个C#脚本,并将其附加到GameObject上。 Animation(动画)组件 作用:创建和控制GameObject的动画。 使用方法:将Animation组件添加到GameObject上,并创建动画剪辑(Animation Clip)。

    1.2K20编辑于 2023-07-30
  • 来自专栏韩曙亮的移动开发专栏

    【Unity3D】Unity 脚本 ④ ( 游戏物体 GameObject 的坐标 | 修改 游戏物体 GameObject 的本地坐标 )

    文章目录 一、 游戏物体 GameObject 的坐标 二、 修改 游戏物体 GameObject 的本地坐标 一、 游戏物体 GameObject 的坐标 ---- 游戏物体 GameObject 的 本地坐标 时 , 使用 this.gameObject.transform.localPosition 代码获取 , 也可使用简化写法 , 省略掉中间的 gameObject , 即 this.transform.localPosition 类型是 Vector3 类型 , 这是一个 三维向量 , 由 3 个 float 浮点型的数值组成 ; 如果要设置 游戏物体 GameObject 的 本地坐标 , 则为其赋值一个 Vector3 类型的 GameObject gameObject = this.gameObject; // 获取当前组件附着的 游戏物体 GameObject 名称 string name = gameObject.name; Debug.Log("C# 脚本附着游戏物体的名称 : " + name); // 获取当前组件附着的 游戏物体 GameObject

    2.3K20编辑于 2023-03-30
  • 来自专栏Unity3d程序开发

    unity3d:ui跟着gameobject移动

    UiFollowObj : MonoBehaviour { Transform m_trans; public Transform m_followTrans; public GameObject

    34130编辑于 2023-08-24
  • 来自专栏Unity3d程序开发

    Unity3D 销毁GameObject api调用顺序

    对于每个GameObject来说,实际调用顺序是OnDisable->OnBecameInvisible->OnDestroy,但是在多个GameObject直接不能保证调用顺序,可能第一个GameObject 所以当多个GameObject调用一个全局变量时,要注意。 YieldEnable() { yield return 1; PenMgr.mInstance.m_isCloneShadow = false; } } 防止下个创建GameObject 时m_isCloneShadow变量被上一个GameObject销毁时又改了回去,就是晚一帧执行

    43730编辑于 2023-08-24
  • 来自专栏算法微时光

    unity3d之使用GameObject添加光源

    image.png GameObject Unity 场景中所有实体的基类。 注意:GameObject 类中的很多变量已被删除。 例如, 要访问 csharp 中的 GameObject.renderer,请改用 GetComponent<Renderer>()。 函数 含义 activeInHierarchy 定义 GameObject 在 Scene 中是否处于活动状态。 activeSelf 此 GameObject 的本地活动状态。 scene 该 GameObject 所属的场景。 tag 此游戏对象的标签。 transform 附加到此 GameObject 的 Transform。 lightAdd = new GameObject(); // 添加光组件 Light lightRed = lightAdd.AddComponent

    78810发布于 2020-11-12
  • 来自专栏Unity3d程序开发

    Unity3d:特效对象池,超时删除池内GameObject,GC权值

    技术要点: 不用的粒子返回缓冲池 按照单个粒子名字创建一个池,当a池上一次操作时间(回收对象)超过阈值,每隔一段时间删除池里一个GameObject,可针对单个粒子配表,频繁使用的,驻留时间更长 一个完整池被删除 ''XXX“ while activating or deactivating the parent GameObject “XXX” ,由于父对象进入回收池时,代码正在对该对象子节点的父节点进行修改 GetEffect(GameObject objPrefab) { string name = GetNoCloneName(objPrefab.name); { obj = GameObject.Instantiate(objPrefab) as GameObject; } obj = GameObject.Instantiate(objPrefab) as GameObject; } obj.SetActive(true);

    58530编辑于 2023-08-24
  • 来自专栏算法微时光

    unity3d之GameObject获取标签对象并修改颜色

    GameObject::FindGameObjectsWithTag GameObject类的静态函数。 作用: 返回标记为 tag 的活动 GameObject 的列表。 如果未找到 GameObject,则返回空数组。 GameObject:::FindWithTag GameObject类的静态函数。 作用:返回一个标记为 tag 的活动 GameObject。 如果未找到 GameObject,则返回 null。 OnGUI() { if (GUILayout.Button("find enery")) { // 根据标签获取对象 GameObject [] enemys = GameObject.FindGameObjectsWithTag("enemy"); // 修改颜色 for (int i =

    2.3K30发布于 2020-11-12
  • 来自专栏韩曙亮的移动开发专栏

    【Unity3D】Unity 游戏画面帧更新 ( 游戏物体 GameObject 移动 | 借助 Time.deltaTime 进行匀速运动 )

    文章目录 一、 游戏物体 GameObject 移动 二、 借助 Time.deltaTime 进行匀速运动 一、 游戏物体 GameObject 移动 ---- 在 Unity 中 , 如果想要让 GameObject gameObject = this.gameObject; // 获取当前组件附着的 游戏物体 GameObject 名称 string name = gameObject.name; Debug.Log("C# 脚本附着游戏物体的名称 : " + name); // 获取当前组件附着的 游戏物体 GameObject GameObject gameObject = this.gameObject; // 获取当前组件附着的 游戏物体 GameObject 名称 string name = gameObject.name; Debug.Log("C# 脚本附着游戏物体的名称 : " + name); // 获取当前组件附着的 游戏物体 GameObject

    1.1K20编辑于 2023-03-30
  • 来自专栏全栈程序员必看

    Slog53_Unity3D之功能脚本_FindOtherGameObjects_找到场景内除自己外的其他GameObject

    开发环境MacOS(High Sierra 10.13.5) 需要的信息和信息源: UnityEngine.SceneManagement Scene GameObject 开始编码 更新后的完整代码: "'."); } } } } } 首先声明一个 Scene对象,当调用脚本的时候,获取当前 Scene对象 再声明一个 GameObject 数组 对象 objs,用来存放当前 Scene里 的所有 GameObject 遍历所有的 GameObject,加入判断,当 Scene里的 GameObject 的name属性不等于自身的时候,执行指定的逻辑 的 name属性了 如果要对自身外的其他 GameObject进行一些操作,更新下面的这行代码就行了: unity3d_script_c#/FindOtherGameobjects.cs Debug.Log ("Active scene have '" + obj.name + "'."); 至此,我们实现了 unity3d 找到场景内除自己外的其他GameObject 的功能。

    39220编辑于 2022-06-29
  • 来自专栏全栈程序员必看

    unity麻将开发视频教程_一屏双人单机手机游戏

    // GameObject root = GameObject.Find("UI Root"); // GameObject parent = root.transform.Find(" hubtn;//胡 private GameObject pengbtn;//碰 private GameObject eatbtn;//吃 private GameObject ("sendbtn").gameObject; addbtn = gameObject.transform.Find("addbtn").gameObject; hubtn = gameObject.transform.Find("hubtn").gameObject; pengbtn = gameObject.transform.Find("pengbtn ").gameObject; eatbtn = gameObject.transform.Find("eatbtn").gameObject; gangbtn = gameObject.transform.Find

    3.3K30编辑于 2022-09-27
  • 来自专栏宜达数字

    Unity项目-水果忍者

    knife; private Vector3 startPos; private Vector3 endPos; private GameObject canver; void Start () { knife = (GameObject)Resources.Load("Prefabs/Knife"); canver = GameObject.Find canvas; // 水果集合 public GameObject[] fruits; void Start () { canvas = GameObject.Find fruit = Instantiate(fruits[index]) as GameObject; fruit.transform.parent = canvas.transform; obj) { // 切到水果了,创建切后的水果对象 GameObject fruit = Instantiate(Resources.Load(path) as

    96420发布于 2020-06-02
  • 来自专栏Unity3d程序开发

    unity3d:ugui双击按钮

    <ClickEventListener>(); } return listener; } System.Action<GameObject > mClickedHandler = null; System.Action<GameObject> mDoubleClickedHandler = null; System.Action <GameObject> mOnPointerDownHandler = null; System.Action<GameObject> mOnPointerUpHandler = null = null) { mClickedHandler(gameObject); } = null) { mOnPointerUpHandler(gameObject); } } }

    55130编辑于 2023-08-24
  • 来自专栏六月-游戏开发

    unity-对象池

    其中首先需要一个容器用于存储对象,这里选用队列就很适合, public Queue<GameObject> pool = new Queue<GameObject>() 然后需要方法预先给容器存放一些对象 public GameObject GetObject() { if (pool.Count == 0) FillPool(); GameObject obj = pool.Dequeue (); obj.SetActive(true); return obj; } public void PutObject(GameObject obj) { obj.SetActive > pool = new Queue<GameObject>(); private GameObject Prefab; //存储对象的Prefab public static GameObject poolGO; //总对象池管理 public ObjectPool(GameObject Prefab,int InitSum = 10,int addSum =

    67840编辑于 2022-12-26
  • 来自专栏章鱼的慢慢技术路

    通过C#脚本实现旋转的立方体

    (Vector3.up * Time.deltaTime * 200); //Cube转动 if(GameObject.Find("Spotlight").GetComponent ,所以在Update函数的if语句里面应添加以下脚本 GameObject.Find("Text").GetComponent<Text>().text = "Cube正在旋转 (Vector3.up * Time.deltaTime * 200); //Cube转动 GameObject.Find("Text").GetComponent<Text> "; if(GameObject.Find("Spotlight").GetComponent<Light>().intensity < 8.0F) { GameObject.Find("Spotlight").GetComponent<Light>().intensity += 0.05F; }

    2.1K60发布于 2018-06-04
  • 来自专栏游戏杂谈

    Unity插件扩展中组件常用的几个方法

    gameObject, Type componentType) { foreach (var component in gameObject.GetComponents<Component go = GameObject.Instantiate(GameObject.Find(strCurrSelectPrefabName)) as GameObject; PrefabUtility.ReplacePrefab ; } else { Debug.Log("当前选中的GameObject命名不符合要求,格式:id+h。 ; 3、销毁老的GameObject; 4、刷新资源; 对于美术的同事来讲,最复杂、麻烦的莫过于重新关联属性,特别是骨骼动画。 通过Name查找某个GameObject下的子节点(前提条件是该Name唯一) public static GameObject FindChildGameObject(GameObject parent

    2.5K10发布于 2018-11-20
  • 来自专栏星河造梦坊专栏

    AR涂涂乐⭐六、 UGUI精灵格式、自动延迟截图、优化“4”、移出扫描框终止截图进程

    ("Canvas").gameObject.GetComponent<CanvasScaler>(); //获取屏幕自适度,GameObjectGameObject.Find("Canvas")这个物体 ,gameObjectGameObject这个物体。 PlaneWH = new Vector2(gameObject.GetComponent<MeshFilter>().mesh.bounds.size.x, gameObject.GetComponent //获得图片的四个点世界坐标(gameobject指的是面片,它的父集是图片)(position是图片中心的位置,所以需要加上面片x,y向长度) TopLeft_pl_w = gameObject.transform.parent.position gameObject.GetComponent<Renderer>().material = Tran_Mate; //将面片由绿色变为透明,除去截图时的影响。

    40810编辑于 2024-08-14
  • 来自专栏U3D

    游戏设计模式——Unity对象池

    >> pool = new Dictionary<string, List<GameObject>>(); 容量是一个常量,最好取二的幂值,这样的话可以刚好占用所有内存位的资源,避免浪费。 下面先定义回收对象的方法: 1 public void RecycleObj(GameObject obj) 2 { 3 var par = Camera.main GameObject perfab) 2 { 3 //池子中有 4 GameObject result = null; 5 if (pool.ContainsKey 和Instantiate方法一样,加一个可以设置父对象的重载方法: 1 public GameObject GetObj(GameObject perfab, Transform parent) >> pool = new Dictionary<string, List<GameObject>>(); 8 9 public GameObject GetObj(GameObject

    4.3K31发布于 2020-03-19
  • 来自专栏韩曙亮的移动开发专栏

    【Unity3D】Unity 脚本 ③ ( C# 脚本的执行入口函数 | 获取当前游戏物体及物体名称 | 获取游戏物体的 Transform 组件数据 | UnityEngine 命名空间简介 )

    , 可以通过调用 this.gameObject 获取当前 C# 脚本附着的物体 , 代码如下 : // 获取当前组件附着的 游戏物体 GameObject GameObject gameObject = this.gameObject; 获取 游戏物体 GameObject 的名称 , 调用 GameObject 类的 name 属性 , 即可获取当前物体的名称 ; // 获取当前组件附着的 游戏物体 GameObject 名称 string name = gameObject.name; 完整代码如下 : using System.Collections GameObject gameObject = this.gameObject; // 获取当前组件附着的 游戏物体 GameObject 名称 string GameObject gameObject = this.gameObject; // 获取当前组件附着的 游戏物体 GameObject 名称 string

    2K10编辑于 2023-03-30
  • 来自专栏Unity3d程序开发

    U3D观察者模式,实现1对多

    / 构造函数 /// /// <param name="param"></param> public Notification(object param,GameObject , OnNotification>> m_dicEvent = new Dictionary<string, Dictionary<GameObject, OnNotification>>(); public void ObjAddEventListener(string eventKey, GameObject obj,OnNotification eventListener) m_dicEvent.ContainsKey(eventKey)) { Dictionary<GameObject, OnNotification> dic = m_dicEvent.ContainsKey(eventKey)) return; List<GameObject> listRemoveKey = new List

    31520编辑于 2023-08-24
领券