public void Unhide() { foreach (GameObject GO in BodyPartsToHide) { GO.SetActive(true); } }
private GameObject GetClosestLink(GameObject joint) { GameObject closest = null; GameObject[] allObjects = FindObjectsOfType <GameObject>(); foreach (GameObject GO in allObjects) { if (GO.GetComponent <RobotLink>() != null) { if (closest == null) { closest = GO; } else { if (Vector3.Distance(joint.transform.position, GO.transform.position) < Vector3.Distance(joint.transform.position, closest.transform.position)) { closest = GO; } } } } return(closest); }
void UpdateDuckMats(int colour) { Material mat = duckYellow; switch (colour) { case (0): mat = duckYellow; break; case (1): mat = duckBlue; break; case (2): mat = duckRed; break; default: break; } foreach (GameObject GO in colourChangeObjects) { GO.GetComponent <Renderer> ().material = mat; } }
void DisableMenu(GameObject[] Golist) { foreach (GameObject GO in Golist) { GO.SetActive(false); } }
// Start is called before the first frame update void Start() { rb = GetComponent <Rigidbody>(); rbOriginalMass = rb.mass; col = GetComponent <CapsuleCollider>(); //GetComponent<LineRenderer>().enabled = false; // Hide "Scarf" currentSpeed = Speed; isAiming = false; // Search for all existing moveable and grapple objects and put them in a dictionary GameObject[] foundMoveableObjects = GameObject.FindGameObjectsWithTag("Moveable"); GameObject[] foundGrappleObjects = GameObject.FindGameObjectsWithTag("Grapple"); tkObjects = new Dictionary <GameObject, Material>(); foreach (GameObject MO in foundMoveableObjects) { tkObjects.Add(MO, MO.GetComponent <MeshRenderer>().material); } foreach (GameObject GO in foundGrappleObjects) { tkObjects.Add(GO, GO.GetComponent <MeshRenderer>().material); } Crosshairs.enabled = false; Cursor.visible = false; Cursor.lockState = CursorLockMode.Confined; distanceGround = GetComponent <CapsuleCollider>().bounds.extents.y; haveLetGoOfMouse = true; GrappleSpeed = 0.05f; stowedObject = false; spawnPosition = transform.position; }
/// <summary> /// loops through all objects in the game's state and ticks each one /// </summary> public void TickAll() { foreach (GameObjects.IGameObject GO in GameObjectList) { GO.Tick(); } }
// 获取控件 protected sealed override void FetchSubjects() { if (GO == null) { return; } if (IsRootView) { return; } //获得所有的控件 var tempControls = GO.GetComponentsInChildren <UControl>(true); if (tempControls != null) { foreach (var item in tempControls) { if (item is UPanel panel) { AddPanel(panel); item.OnBeFetched(); } else if (item.IsCanBeViewFetch) { AddControl(item); item.OnBeFetched(); } } } }
public bool GenerateCube(GameObject GO) { MeshFilter CubeMeshFilter = null; if (!GO) { GO = new GameObject(); CubeMeshFilter = GO.AddComponent <MeshFilter>(); CubeMesh = CubeMeshFilter.mesh; MeshRenderer MyMeshRenderer = GO.AddComponent <MeshRenderer>(); GO.transform.localScale = new Vector3(1, 1, 1); } else { CubeMeshFilter = GO.GetComponent <MeshFilter>(); if (CubeMeshFilter) { CubeMesh = CubeMeshFilter.mesh; } } if (CubeMeshFilter && CubeMesh) { Cube_vertices = new List <Vector3>(); Cube_triangles = new List <int>(); Cube_CreateCube(GO); } CustomMessage = ""; return(true); }
public bool GenerateCylinder(GameObject GO) { if (!GO) { GO = new GameObject(); Cylinder_MeshFilter = GO.AddComponent <MeshFilter>(); Cylinder_Mesh = Cylinder_MeshFilter.mesh; MeshRenderer MyMeshRenderer = GO.AddComponent <MeshRenderer>(); //need to set the material up top MyMeshRenderer.material = planetMaterial; GO.transform.localScale = new Vector3(1, 1, 1); } else { Cylinder_MeshFilter = GO.GetComponent <MeshFilter>(); if (Cylinder_MeshFilter) { Cylinder_Mesh = Cylinder_MeshFilter.mesh; } } if (Cylinder_MeshFilter && Cylinder_Mesh) { Cylinder_MakingVertices(1, iter, leng, 0.5f, 0.1f); } CustomMessage = ""; return(true); }
void Start() { PanelComponents = new List <OnePanel> (); objectMover = gameObject.AddComponent <ObjectManipulation> (); foreach (GameObject GO in PanelsToSwap) { OnePanel temp; temp.baseGameObject = GO; temp.AllColliders = GO.GetComponentsInChildren <Collider2D>(); temp.AllSpriteRenderers = GO.GetComponentsInChildren <SpriteRenderer>(); PanelComponents.Add(temp); // GO.transform.position = (Vector3)(Vector2)GO.transform.position + new Vector3(0,0,OffsetCounter); GO.transform.localPosition = new Vector3(0, 0, DistanceBetweenPanels * (MaxPanelIndex + 1)); OffsetCounter += DistanceBetweenPanels; MaxPanelIndex++; if (MaxPanelIndex != 0) { SetAllColliders(PanelComponents[MaxPanelIndex], false); SetSpriteAlpha(PanelComponents[MaxPanelIndex], 0.5f); } } CurrentActivePanel = 0; // foreach(OnePanel aPanel in PanelComponents) // { // print (string.Format ("{0}. Colliders = {1}. SpriteRenderers = {2}", aPanel.baseGameObject, aPanel.AllColliders.Length, aPanel.AllSpriteRenderers.Length)); // // } }
float CostEstimater(GameObject[] inputs, float count) { float estimatedCost = 0; int ctr = 0; foreach (GameObject item in inputs) { if (item.GetComponent <RawMaterial>()) { estimatedCost += item.GetComponent <RawMaterial>().Price *count; } else { GameObject[] inputsOfMaterial = item.GetComponent <MealMaterial>().Inputs; float inputCnt = item.GetComponent <MealMaterial>().InputCount[ctr]; foreach (GameObject GO in inputsOfMaterial) { if (GO.GetComponent <RawMaterial>()) { estimatedCost += GO.GetComponent <RawMaterial>().Price *inputCnt *count; } else { GameObject[] inputsOfMaterialOFMaterial = GO.GetComponent <MealMaterial>().Inputs; foreach (GameObject GOO in inputsOfMaterialOFMaterial) { estimatedCost += CostEstimater(inputsOfMaterialOFMaterial, inputCnt); } } } } ctr++; } return(estimatedCost); }
void OnDestroy() { --Coin.CoinCount; //Check remaining coins if (Coin.CoinCount <= 0) { //Game is won. Collected all coins //Destroy Timer and launch fireworks GameObject Timer = GameObject.Find("LevelTimer"); Destroy(Timer); GameObject[] FireworkSystems = GameObject.FindGameObjectsWithTag("Fireworks"); if (FireworkSystems.Length <= 0) { return; } foreach (GameObject GO in FireworkSystems) { GO.GetComponent <ParticleSystem>().Play(); } } }
/// <summary> /// Generic message handler to process options. /// </summary> /// <param name="msg"></param> protected void handleMsg(string msg) { GameObject GO; if (this.otherTarget == null) { GO = this.gameObject; } else { GO = this.otherTarget; } if (this.debugLevel > DEBUG_LEVELS.Off) { Debug.Log(string.Format("Sending message '{0}' to '{1}'", msg, GO)); } if (this.messageMode == MESSAGE_MODE.Send) { GO.SendMessage(msg, SendMessageOptions.DontRequireReceiver); } else { GO.BroadcastMessage(msg, SendMessageOptions.DontRequireReceiver); } }
public static List <T> FindAllPrefabInstancesWithType <T>(UnityEngine.Object myPrefab) { List <T> result = new List <T>(); GameObject[] allObjects = (GameObject[])Resources.FindObjectsOfTypeAll(typeof(GameObject)); foreach (GameObject GO in allObjects) { #if UNITY_EDITOR if (PrefabUtility.GetPrefabType(GO) == PrefabType.PrefabInstance) { if (CheckGameObjectIsParentObject(GO, (GameObject)myPrefab)) { if (GO.GetComponent <T>() != null) { result.Add(GO.transform.GetComponent <T>()); } } } #endif if (Application.isPlaying && !Application.isEditor) { if (CheckGameObjectIsParentObject(GO, (GameObject)myPrefab)) { if (GO.GetComponent <T>() != null) { result.Add(GO.transform.GetComponent <T>()); } } } } return(result); }
private void OnSpawn(bool isFruit) { float x = Random.Range(-8.2f, 8.2f); float y = -5f; float z = tempZ; tempZ -= 2; if (tempZ <= -10) { tempZ = 0; } int index = Random.Range(0, fruits.Length); GameObject GO; if (isFruit) { GO = Instantiate(fruits[index], new Vector3(x, y, z), Quaternion.identity); } else { GO = Instantiate(boom, new Vector3(x, y, 0), Quaternion.identity); } Vector3 vel = new Vector3(-x * Random.Range(0.2f, 0.8f), -Physics.gravity.y * Random.Range(1, 1.4f), 0); rb = GO.GetComponent <Rigidbody>(); rb.velocity = vel; }
private void DesactivarGameObjects() { foreach (var GO in listaGameObjects) { GO.SetActive(false); } }
/// <summary> /// loops through all objects in the game's state and starts each one /// </summary> public void StartAll() { foreach (GameObjects.IGameObject GO in GameObjectList) { GO.Start(); } }
public override void FixedUpdate() { if (moving) { if (velocity < NPCSpeed) { velocity += .01f; } else { velocity = NPCSpeed; } } else { velocity = 0; } if (animator == null) { animator = GO.GetComponent <Animator>() as Animator; } else { animator.SetFloat("runSpeed", velocity); } }
void SendDataToPlayers() { string dataToSend = ""; foreach (GameObject[] GOarray in WallArray) { foreach (GameObject GO in GOarray) { WallScript ws = GO.GetComponent <WallScript>(); int r = ws.getRow(); int c = ws.getCol(); dataToSend += r + "," + c + "," + ws.GetHeight() + "|"; } dataToSend = dataToSend.Substring(0, dataToSend.Length - 1); //Debug.Log("Sending data: "+ dataToSend); networkView.RPC("setMaze", RPCMode.Others, dataToSend); dataToSend = ""; //Had to send the data at the end of every Row, turns out //that 4080 something characters was the maximum string allowed //to be sent through RPC calls. } networkView.RPC("setMaze", RPCMode.Others, "DONE"); }
private void killThisNPC() { //do all the calculations/etc here //drop the items here //etc etc if (this.IsNotAFreaking <Player>()) { CreateTextMessage(Name + " is dead!", Color.red); Debug.Log(this.Name + " was killed!"); //time effects need cleared List <Item> itemsToDrop = new List <Item>(); foreach (InventoryCategory ic in Inventory.Values) { foreach (Item i in ic.Values) { Debug.Log("Adding to drop list: " + i.Name); itemsToDrop.Add(i); } } foreach (Item i in itemsToDrop) { Debug.Log("Dropping item: " + i.Name); this.dropItem(i, GridSpace); } JustUnregister(); animator.Play(deathState); GO.AddComponent <TimedAction>().init(1.5f, new Action(() => { JustDestroy(); })); } else { Debug.Log("Player is dead! Uhh, what do we do now?"); } }
public override void Awake() { base.Awake(); graphics = GetComponentsInChildren <Graphic>(); canvasGroup = GetComponent <CanvasGroup>(); if (canvasGroup == null && RectTrans != null) { canvasGroup = GO.AddComponent <CanvasGroup>(); } LayoutGroup = GetComponent <LayoutGroup>(); //初始化变化组件 EffectShows.AddRange(PosAnimator); EffectShows.AddRange(ScaleAnimator); foreach (var item in EffectShows) { item.Init(this); } sourceAnchorMax = RectTrans.anchorMax; sourceAnchorMin = RectTrans.anchorMin; sourceLocalScale = RectTrans.localScale; sourceSizeData = RectTrans.sizeDelta; sourceAnchoredPosition = RectTrans.anchoredPosition; sourceAnchoredPosition3D = RectTrans.anchoredPosition3D; sourcePivot = RectTrans.pivot; }
void PentacleEnded() { foreach (GameObject GO in objectsToActivate) { GO.SetActive(true); } if (pentacleFail) { dialogues.shouldWrite = true; dialogues.sequence = 4; pentacle.material = completePentacle; } else { dialogues.shouldWrite = true; dialogues.sequence = 3; pentacle.material = completePentacle; } dessinage.dessinage = false; if (pentacleFail) { Destroy(gameObject); GoodDessin = false; } else { GoodDessin = true; } particles.Play(); pentacleDone = false; }
void EnableMenu(GameObject[] Golist) { foreach (GameObject GO in Golist) { GO.SetActive(true); } }
public void EnableCollectables() { foreach (GameObject GO in collectibles) { GO.SetActive(true); } }
private GameObject GetClosestJoint(GameObject link) { GameObject closest = null; GameObject[] allObjects = FindObjectsOfType <GameObject>(); foreach (GameObject GO in allObjects) { if (GO.GetComponent <ObjectJoint>() != null && GO.activeInHierarchy) { if (closest == null) { closest = GO; } else { if (Vector3.Distance(link.transform.position, GO.transform.position) < Vector3.Distance(link.transform.position, closest.transform.position)) { closest = GO; } } } } return(closest); }
//from http://answers.unity3d.com/questions/209472/detecting-when-all-rigidbodies-have-stopped-moving.html //modified by Marshall Mason IEnumerator CheckObjectsHaveStopped() { Rigidbody2D[] GOS = FindObjectsOfType(typeof(Rigidbody2D)) as Rigidbody2D[]; bool allSleeping = false; while (!allSleeping) { allSleeping = true; GOS = FindObjectsOfType(typeof(Rigidbody2D)) as Rigidbody2D[]; foreach (Rigidbody2D GO in GOS) { if (!GO.IsSleeping()) { allSleeping = false; yield return(null); break; } } } yield return(new WaitForSeconds(1)); trackingShot = false; if (player != null) { Destroy(player.gameObject); } }
private void SpawnVFX(Vector3 hitInfoPoint) { if (clickVFX == null) { return; } GameObject GO; if (_clickVFXPool.Count > 0) { int lastElement = _clickVFXPool.Count - 1; GO = _clickVFXPool[lastElement]; _clickVFXPool.RemoveAt(lastElement); GO.SetActive(true); GO.transform.position = hitInfoPoint; } else { GO = Instantiate(clickVFX, hitInfoPoint, Quaternion.identity, gameObject.transform); } StartCoroutine(DisableAfter(GO, clickVFXDuration)); }
public void Ready(Messenger msg) { Assert.AreEqual(cam.orthographicSize, 11f, "Camera should have an orthographic size " + "of 11 due to the import settings of the " + "graphics."); float colliderHeight = cam.orthographicSize * 2f; float colliderWidth = colliderHeight * cam.aspect + boundsWidth; panning = GO.Create("CameraPanning") .AddComponent <CameraPanning>(cp => { cp .Init(new CameraPanningConfig { camera = cam, tapThreshold = 1.5f, scale = new Vector3(colliderWidth, colliderHeight, 0f), inertiaDuration = 2f }); }) .SetLayer("Default") .SetParent(transform) .SetLocalPosition(new Vector3(0f, 0f, cam.transform.position.z + 1f)) .GetComponent <CameraPanning>(); dayStart = dayNightCycle.keys[1].time; nightStart = dayNightCycle.keys[2].time; msg.Dispatch(new MCameraReady { camera = cam }); msg.Dispatch(new MAddUpdateHandler(this)); }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // * New Method: Update Labels //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void UpdateLabels() { if (PlayerControlsInstance.m_uiPlayerScore != m_uiScore) { RunScorePopup(); m_uiScore = PlayerControlsInstance.m_uiPlayerScore; m_uiScoreCount.text = "Score: " + m_uiScore.ToString(); } if (m_fHealthPercentage != PlayerControlsInstance.m_fHealth && PlayerControlsInstance.m_fHealth > 0) { // Play Alarm if Low Health. Only Play Once if (PlayerControlsInstance.m_fHealth < 20f && m_fHealthPercentage >= 20f) { m_HealthAlarmSource.Play(); } // Back to Full Health after Dying? if (PlayerControlsInstance.m_fHealth > 99.9f) { foreach (GameObject GO in m_HealthObjects) { GO.GetComponent <Visuals>().Reset(); GO.GetComponent <Visuals>().m_eHealthVisState = Visuals.eHealthVis.FINE; } } m_uiHealthPercenatge.text = "Health: " + GetHealthColour() + ((int)m_fHealthPercentage).ToString() + "%"; } }
public void UIDisable() { foreach (GameObject GO in UI) { GO.SetActive(false); } }