public static FindGameObjectWithTag ( string tag ) : |
||
tag | string | |
Результат |
public void GameOver() { mainCanvas.SetActive(false); gameOverCanvas.SetActive(true); gameOverCanvas.transform.GetChild(0).gameObject.SetActive(true); GameObject.FindGameObjectWithTag("PersistentBoi")?.GetComponent <MusicIntro>()?.KillBGM(); //Time.timeScale = 0; }
private void Start() { //DataController.SaveValue("SkillPoints", 10000); //DataController.SaveValue("Bread", 10000); //DataController.SaveValue("Exp", 10000); SpecialsMenu = GameObject.FindGameObjectWithTag("SpecialsPanel"); Texts = CharacterInfo.GetComponentsInChildren <Text>(); //Debug.Log(Texts.Length); SpecialsMenu.SetActive(false); StatsBars.SetActive(false); }
// Update is called once per frame void Update() { EnemyHealthBar.value = EnemyHealth; //sets equal the value of the slider to the enemies health (EnemyHealth) EnemyHealthBar.transform.LookAt(GameObject.FindGameObjectWithTag("Player").transform); //the EnemyHealthBar looks at the game object with the tag Player if (EnemyHealth <= 0) //checks if EnemyHealth is less than or equal to 0 { MyAgent.destination = transform.position; // sets MyAgents destination to this objects position (or stops it from moving) gameObject.GetComponentInChildren <Animator>().SetTrigger("Die"); //gets the child animator component and triggers Die Destroy(gameObject, 3); //destroys the game object this script is attached to after 3 seconds //gameObject.SetActive(false); } if (EnemyHealth > 0) // checks if EnemyHealth is greater than 0 { if (Vector3.Distance(MyAgent.destination, transform.position) <= 2) //checks if the distance from the destination and itself is less than or equal to 2 { CurrentWaypoint++; //adds 1 to currentwaypoint } if ((Vector3.Distance(MyAgent.destination, transform.position) >= 2) && (Vector3.Distance(MyAgent.transform.position, GameObject.FindGameObjectWithTag("Player").transform.position) >= 7)) //checks if distance from MyAgents destination to its position is greater than or equal to 2 and its position to the players position is greater than or equal to 7 { if (CurrentWaypoint >= waypoints.Length ) //checks if currentwaypoint is greater than or equal to waypoints array length { CurrentWaypoint = 0; //sets currentwaypoint to 0 } MyAgent.destination = waypoints[CurrentWaypoint].transform .position; //sets MyAgents destination equal to the waypoint in the CurrentWayPoint position } else { MyAgent.destination = GameObject.FindGameObjectWithTag("Player").transform.position; //sets MyAgents destination to the object with the Player tags position if (Vector3.Distance(MyAgent.transform.position, GameObject.FindGameObjectWithTag("Player").transform.position) <= 2) // checks if MyAgents distance from the object with the Player tags position is less than 2 { gameObject.GetComponentInChildren <Animator>().SetTrigger("Close"); //gets the child animator component and triggers Close } else { gameObject.GetComponentInChildren <Animator>().SetTrigger("NotClose");//gets the child animator component and triggers NotClose } } } }
void Start() { for (int i = 0; i < gameObject.transform.childCount; i++) { if (gameObject.transform.GetChild(i).gameObject.name == "Bounds") { bounds = gameObject.transform.GetChild(i).gameObject; continue; } if (gameObject.transform.GetChild(i).gameObject.name == "Walls") { walls = gameObject.transform.GetChild(i).gameObject; continue; } if (gameObject.transform.GetChild(i).gameObject.name == "Obstacle") { obstacles = gameObject.transform.GetChild(i).gameObject; continue; } if (gameObject.transform.GetChild(i).gameObject.name == "ScoreBounds") { scoreBounds = gameObject.transform.GetChild(i).gameObject; continue; } } if (gameObject.transform.GetChild(0).gameObject.name == "Walls") { walls = gameObject.transform.GetChild(0).gameObject; obstacles = gameObject.transform.GetChild(1).gameObject; } else { walls = gameObject.transform.GetChild(1).gameObject; obstacles = gameObject.transform.GetChild(0).gameObject; } for (int i = 0; i < walls.transform.childCount; i++) { if (walls.transform.GetChild(i).gameObject.name == "Right") { rightWall = walls.transform.GetChild(i).gameObject; continue; } if (walls.transform.GetChild(i).gameObject.name == "Ground") { ground = walls.transform.GetChild(i).gameObject; continue; } if (walls.transform.GetChild(i).gameObject.name == "Left") { leftWall = walls.transform.GetChild(i).gameObject; continue; } } scoreCounted = false; player = GameObject.FindGameObjectWithTag("PlayerTag"); scriptHandler = GameObject.FindGameObjectWithTag("ScriptHandler"); scoreHandler = scriptHandler.GetComponent <ScoreHandler>(); gameHandler = scriptHandler.GetComponent <GameHandler>(); mapHandler = scriptHandler.GetComponent <MapHandler>(); if (gameObject.name.Contains("GasStation")) { activeObstacles = new List <GameObject>() { }; return; } for (int i = 0; i < obstacles.transform.childCount; i++) { if (obstacles.transform.GetChild(i).gameObject.name == "Left") { leftObstacle = obstacles.transform.GetChild(i).gameObject; continue; } if (obstacles.transform.GetChild(i).gameObject.name == "Mid") { middleObstacle = obstacles.transform.GetChild(i).gameObject; continue; } if (obstacles.transform.GetChild(i).gameObject.name == "Right") { rightObstacle = obstacles.transform.GetChild(i).gameObject; continue; } } activeObstacles = new List <GameObject>() { leftObstacle, middleObstacle, rightObstacle }; int currentLevel = gameHandler.HardnessLevel; int numLevels = gameHandler.IncreaseHardnessAtNumObjects.Count; int maxPossibleNumObstacles = 2; int maxNumObstacles = Mathf.CeilToInt(maxPossibleNumObstacles * (currentLevel / (float)numLevels)); int minNumObstacles = Mathf.FloorToInt(maxPossibleNumObstacles * (currentLevel / (float)numLevels)); int numberOfObstacles = Random.Range(minNumObstacles, maxNumObstacles + 1); int amountToTakeAway = activeObstacles.Count - numberOfObstacles; HashSet <int> usedIndexes = new HashSet <int>(); while (usedIndexes.Count != amountToTakeAway) { int randInt = Random.Range(0, activeObstacles.Count); if (usedIndexes.Contains(randInt)) { continue; } activeObstacles[randInt].SetActive(false); usedIndexes.Add(randInt); } for (int i = 0; i < activeObstacles.Count; i++) { if (!activeObstacles[i].activeSelf) { activeObstacles.RemoveAt(i); i = i - 1; } else { GameObject carSprite = activeObstacles[i].transform.GetChild(0).gameObject; carSprite.GetComponent <SpriteRenderer>().material = Instantiate(gameHandler.carMaterial as Material); Color c = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), 1); carSprite.GetComponent <SpriteRenderer>().material.SetColor("_Color", c); } } }
public static GameObject FindWithTag(string tag) { return(GameObject.FindGameObjectWithTag(tag)); }