void Start() { //Set variables _gameController = GameObject.Find("GameController").GetComponent <GameController>(); canvas = transform.Find("Canvas"); _scoreText = canvas.Find("Text").GetComponent <TextMeshProUGUI>(); _spriteRenderer = transform.Find("Square").GetComponent <SpriteRenderer>(); _ropeMovement = GameObject.Find("RopeTop").transform.Find("RopeMiddle").Find("RopeBot").GetComponent <RopeMovement>();; //Set the color of the build in order Blue -> Red -> Green -> Blue -> Red, and goes on... var ran = _ropeMovement.numbOfChilds % 3; switch (ran) { //Case variable that defines color is 0 (blue) case 0: //If blue already lose... if (_gameController.bluePlayerLose) { //...Instantiate another building and destroy this. _ropeMovement.InstantiateBuilding(); Destroy(gameObject); } //If is blue is on game... //Set the color to blue; _spriteRenderer.color = new Color(0.14f, 0.33f, 0.80f); //Set wich floor this block can attach; _goToThisFloor = "B"; //Set the number of the build; buildingNumber = _ropeMovement.numbOfChilds - 4; return; //than do the same for red and green case 1: if (_gameController.redPlayerLose) { _ropeMovement.InstantiateBuilding(); Destroy(gameObject); } _spriteRenderer.color = new Color(0.80f, 0.14f, 0.30f); _goToThisFloor = "R"; buildingNumber = _ropeMovement.numbOfChilds - 4; return; case 2: if (_gameController.greenPlayerLose) { _ropeMovement.InstantiateBuilding(); Destroy(gameObject); } _spriteRenderer.color = new Color(0.33f, 0.60f, 0.14f); _goToThisFloor = "G"; buildingNumber = _ropeMovement.numbOfChilds - 4; return; } }
//Checks when collide occurs private void OnCollisionEnter2D(Collision2D other) { //If other building wasn't spawned if (!spawnedOtherPredio) { //Spawn a build _ropeMovement.InstantiateBuilding(); //Set true the bool that checks if the building is spawned spawnedOtherPredio = true; } //decreases velocity and invert in Y axis velX /= 2; velY = -velY / 2; landed = true; spawnedOtherPredio = true; }