void Update() { if (Input.GetKeyDown(KeyCode.Space) || Input.acceleration.magnitude > maxAcceleration) { if (isReachTop) { ShowOverUI(true); } else { ShowContinueUI(true); } Pause(true); FallApple(); } if (isPause) { return; } Vector3 targetPos; MathfHelper.GetScreenPos(out targetPos, transform.position); guidSprite.transform.position = targetPos; if (Input.GetMouseButtonDown(0) && _maxNum < maxNum) { _maxNum++; trunkParentList.Add(new GameObject("Tree" + trunkCount.ToString()).transform); GameObject go = Instantiate(trunkPrefab); go.transform.position = new Vector3(targetPos.x, bornPos.position.y, 0); go.transform.SetParent(trunkParentList[trunkCount]); Branch branch = new Branch(go); List <Branch> branchList = new List <Branch>(); branchList.Add(branch); trunkDic.Add(trunkCount, branchList); trunkCount++; //======================================== rootParentList.Add(new GameObject("Root" + rootCount.ToString()).transform); GameObject root = Instantiate(rootPrefab); root.transform.position = new Vector3(targetPos.x, bornPos.position.y, 0); root.transform.SetParent(rootParentList[rootCount]); Branch rootBranch = new Branch(root); List <Branch> rootList = new List <Branch>(); rootList.Add(rootBranch); rootDic.Add(rootCount, rootList); rootCount++; } ControlPlants(trunkDic, Type.Branch); ControlPlants(rootDic, Type.Root); }
void Update() { Vector3 targetPos; MathfHelper.GetScreenPos(out targetPos, transform.position); if (Input.GetMouseButtonDown(1)) { GameObject go = Instantiate(applePrefab); go.transform.position = targetPos; } }
GameObject createInstance(Vector3 pos, Camera cam) { float[] weightings = ToCreate.Select(w => w.RandomWeighting).ToArray(); int i = MathfHelper.BiasedRandom(weightings); GameObject go = ToCreate[i].PrefabToCreate; if (CreateAbove > 0f) { pos = pos.UpTowards(cam.transform.position, upDir, CreateAbove); } return((GameObject)Instantiate(go, pos, go.transform.rotation)); }
public static void SetRolePos(float curTime, ObjectContain contain, LCharacterInterface character, LChatacterInformationInterface information, ref Vector3 beginGroundLinePos, Vector3 beginLocalScale, Quaternion beginLocalRot, bool fixBeginPos = true) { if (null != contain.gameobject) { //初始位置 var oldPos = contain.gameobject.transform.position; contain.gameobject.transform.position = beginGroundLinePos; contain.gameobject.transform.localScale = beginLocalScale; contain.gameobject.transform.localRotation = beginLocalRot; //位置转向缩放 contain.gameobject.transform.position = contain.gameobject.transform.localToWorldMatrix.MultiplyPoint(contain.pos); contain.gameobject.transform.localRotation *= contain.rot; contain.gameobject.transform.localScale = MathfHelper.Vector3Mul(beginLocalScale, contain.scale); //旧技能位置在水平线上的位置. var old_h_pos = oldPos; old_h_pos.y = beginGroundLinePos.y; //新技能位置在水平线上的位置 var new_h_pos = contain.gameobject.transform.position; new_h_pos.y = beginGroundLinePos.y; var _dir = new_h_pos - old_h_pos; if (fixBeginPos) { //技能贴地运动 var new_h_pos1 = information.tryMove(old_h_pos, _dir, true); var _delta = new_h_pos1 - new_h_pos; beginGroundLinePos = new Vector3(beginGroundLinePos.x + _delta.x, new_h_pos1.y, beginGroundLinePos.z + _delta.y);//修正技能水平线高度 contain.gameobject.transform.position = new Vector3(new_h_pos1.x, contain.gameobject.transform.position.y, new_h_pos1.z); } else { //技能贴地运动 new_h_pos = information.tryMove(old_h_pos, _dir, true); beginGroundLinePos = new Vector3(beginGroundLinePos.x, new_h_pos.y, beginGroundLinePos.z);//修正技能水平线高度 contain.gameobject.transform.position = new Vector3(new_h_pos.x, contain.gameobject.transform.position.y, new_h_pos.z); } } }