Пример #1
0
 void Start()
 {
     //set variables
     lastRope         = GameObject.Find("RopeTop").transform.Find("RopeMiddle").Find("RopeBot");
     lastRopeMovement = lastRope.GetComponent <RopeMovement>();
     _rigidbody2D     = GetComponent <Rigidbody2D>();
     //set gravity to 0 to the building block don't go down while on the rope
     _rigidbody2D.gravityScale = 0;
     _ropeMovement             = lastRope.GetComponent <RopeMovement>();
 }
Пример #2
0
    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;
        }
    }