public static GetChild ( string name, Transform t ) : Transform | ||
name | string | |
t | Transform | |
Résultat | Transform |
private void OnGUI() { if (GUILayout.Button("find the enemy with lowest HP")) { // find all enemy Enemy[] allEnemy = Object.FindObjectsOfType <Enemy>(); // find the min enemy Enemy min = FindEnemyByMinHp(allEnemy); // sign the enemy min.GetComponent <MeshRenderer>().material.color = Color.red; } if (GUILayout.Button("层级未知,查找子物体")) { var childTF = TransformHelper.GetChild(this.transform, "Cubexx"); childTF.GetComponent <MeshRenderer>().material.color = Color.red; } if (GUILayout.Button("暂停游戏")) { Time.timeScale = 0; } if (GUILayout.Button("继续游戏")) { Time.timeScale = 1; } }
private void OnGUI() { if (GUILayout.Button("暂停")) { Time.timeScale = 0; } if (GUILayout.Button("继续")) { Time.timeScale = 1; } if (GUILayout.Button("查找最少血量")) { Enemy[] diRen = GameObject.FindObjectsOfType <Enemy>(); Enemy min = ChaZhaoXueLiang(diRen); min.GetComponent <MeshRenderer>().material.color = Color.yellow; } if (GUILayout.Button("查找子/孙物体")) { var cube = TransformHelper.GetChild(this.transform, "Cube4"); Debug.Log(cube); cube.GetComponent <MeshRenderer>().material.color = Color.blue; } if (GUILayout.Button("查找距离最近物体")) { Enemy[] enemy = GameObject.FindObjectsOfType <Enemy>(); Enemy dis = FindEnemyMinBuyDistance(enemy); dis.GetComponent <MeshRenderer>().material.color = Color.black; } }
private void InitCtrl(GameObject playerObj) { // testMove move = playerObj.GetComponent<testMove>(); // ETCJoystick j = ETCInput.GetControlJoystick("MyJoystick"); // // ETCTouchPad t = ETCInput.GetControlTouchPad("TouchPad"); // ETCButton b2 = ETCInput.GetControlButton("AttackBtn"); // b2.onDown.AddListener(move.OnAttack); // j.onMove.AddListener(move.OnMove); // j.onMoveEnd.AddListener(move.OnMoveEnd); PlayerCtrl PlayerCtrl = playerObj.AddComponent <PlayerCtrl>(); ETCJoystick j = ETCInput.GetControlJoystick("MyJoystick"); // ETCTouchPad t = ETCInput.GetControlTouchPad("TouchPad"); ETCButton b2 = ETCInput.GetControlButton("AttackBtn"); b2.onDown.AddListener(PlayerCtrl.OnAttack); j.onMove.AddListener(PlayerCtrl.OnMove); j.onMoveEnd.AddListener(PlayerCtrl.OnMoveEnd); // playerObj.transform.position = Camera.main.transform.parent.position; // playerObj.transform.parent = Camera.main.transform.parent; follow f = Camera.main.GetComponent <follow>(); Transform cameraPoint = TransformHelper.GetChild(playerObj.transform, "cameraPoint"); f.SetTarget(cameraPoint.gameObject); littleMapCamera subCamera = GameObject.FindGameObjectWithTag("LittleMapCamera").GetComponent <littleMapCamera>(); subCamera.SetTarget(cameraPoint.gameObject); }
public Transform GetTransform(string __name, Transform parent) { _target = TransformHelper.GetChild(parent, __name); return(_target); #region /*Transform _root = parent; * Transform _target = parent.Find(__name); * if (_target == null) * { * int count = _root.childCount; * for (int i = 0; i < count; i++) * { * Transform _t = _root.GetChild(i); * _target = _t.Find(__name); * if (_target != null) * { * //Debug.Log("find transform -------------------------------------- :"+ _target.name); * return _target; * } * else * { * _target = GetTransform(__name, _t); * if (_target != null) return _target; * } * } * } * return _target;*/ #endregion }
private void OnGUI() { if (GUILayout.Button("层级未知,查找子物体")) { Transform childTF = TransformHelper.GetChild(this.transform, "TFHelper (5)"); if (childTF != null) { childTF.GetComponent <MeshRenderer>().material.color = Color.red; } else { print("没有这个子物体。"); } } }
private void OnGUI() { if (GUILayout.Button("查找血量最低的敌人")) { Enemy[] allEnemy = Object.FindObjectsOfType <Enemy>(); Enemy min = FindEnemyByMinHP(allEnemy); min.GetComponent <MeshRenderer>().material.color = Color.red; } if (GUILayout.Button("层级未知,查找子物体")) { var childTF = TransformHelper.GetChild(this.transform, "ww"); childTF.GetComponent <MeshRenderer>().material.color = Color.blue; print(childTF.transform.name); } }