Пример #1
0
 public void KillTouchedOtherCube(OtherCube otherCube) => otherCubes.Remove(otherCube);
Пример #2
0
    private void OnTriggerEnter(Collider other)
    {
        //WALL
        if (other.gameObject.layer == 3)
        {
            xDir = xNegativeDir = zDir = zNegativeDir = true;

            canMove      = true;
            _rb.velocity = Vector3.zero;
            Wall  wall = other.GetComponent <Wall>();
            float x    = transform.position.x;
            float z    = transform.position.z;

            for (int i = 0; i < _ignoreColliders.Count; i++)
            {
                _ignoreColliders[i].enabled = true;
            }
            _ignoreColliders.Clear();

            if (wall.ignoreColliders.Count > 0)
            {
                foreach (var ignoreCollider in wall.ignoreColliders)
                {
                    _ignoreColliders.Add(ignoreCollider);
                    ignoreCollider.enabled = false;
                }
            }

            SetWallDir(other);

            if (wall.change == Changer.ChangeX)
            {
                x = (xDir || xNegativeDir) ? wall.wallTransform.position.x : x;
            }
            if (wall.change == Changer.ChangeZ)
            {
                z = (zDir || zNegativeDir) ? wall.wallTransform.position.z : z;
            }

            if (_canSetTransform)
            {
                transform.position = new Vector3(x, transform.position.y, z);
                _canSetTransform   = false;
                Invoke(nameof(TrueCanSetTransform), 0.2f);
            }
        }

        //OTHER CUBE
        if (other.gameObject.layer == 7)
        {
            OtherCube otherCube = other.GetComponent <OtherCube>();

            if (otherCube.currentNum == currentNum)
            {
                _gm.AddDiamonds();
                currentNum  += otherCube.currentNum;
                numText.text = currentNum.ToString();
                _gm.ChangeCurrentLevelOtherCubesColor();
                _gm.CurrentLevel.KillTouchedOtherCube(otherCube);
                _soundManager.PlaySound(_soundManager.collectSound);
                Destroy(other.gameObject);
                UIManager.instance.LevelLineUp();
                if (_gm.CurrentLevel.otherCubes.Count <= 0)
                {
                    _gm.Win();
                }
            }
            else
            {
                _gm.LoseCollided();
                Destroy(gameObject);
            }
        }

        //LEVER BTN
        if (other.gameObject.layer == 8)
        {
            other.transform.localPosition           = Vector3.zero;
            other.GetComponent <LeverBtn>().enabled = true;
            other.GetComponent <Collider>().enabled = false;
        }
    }