//it detect the player void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag("Player")) { //assign the playerObj value playerObj = other.GetComponent<CubeController>(); } }
//it detect the player void OnTriggerExit2D(Collider2D other) { if (other.CompareTag("Player")) {//remove the playerObj value playerObj = null; } }
// Update is called once per frame void Update() { //checks is player is not active and game over is false if (!cube.gameObject.activeInHierarchy && !GameManager.instance.gameOver) { cube = GameObject.FindGameObjectWithTag("Player").GetComponent<CubeController>(); } if (cube.direction == Vector3.right) { direction = Vector3.left; } else { direction = Vector3.right; } //if game is not over and game is started if (!GameManager.instance.gameOver && GameManager.instance.gameStarted) transform.Translate(direction * speed * Time.deltaTime);//move }
void OnTriggerEnter2D(Collider2D other) {//check if the triggering object is player if (other.CompareTag("Player")) {//get the ref to the object CubeController cube = other.GetComponent<CubeController>(); //check the color ind of player and parent tile if (parentTile.colorInd == cube.colorInd) {//if same //here we increase score , change cube color , move all tiles to equal level GameManager.instance.currentScore += (GameManager.instance.level); ChangeCubePlayerColor(); //make all the objects with lerpcolor script blink for (int i = 0; i < lerpColorObjectList.Length; i++) { lerpColorObjectList[i].blink = true; } //move all the other tiles up for (int i = 0; i < tileList.Length; i++) { if (tileList[i].name != parentName) { if (tileList[i].transform.position.y < parentTile.transform.position.y) { tileList[i].MoveUp(0.3f * speedRatio); } } } } else //if not same then game is over { //game over GameManager.instance.gameOver = true; GameManager.instance.gameStarted = false; } } gameObject.SetActive(false); }
private bool hitLeft = false; //this is just to make hitbywall increase by one #endregion void Awake() { if (instance == null) instance = this; }
// Use this for initialization void Start() {//ref to the playe in the scene cube = GameObject.FindGameObjectWithTag("Player").GetComponent<CubeController>(); }
// Use this for initialization void Start() {//get ref to the player cubePlayer = GameObject.FindGameObjectWithTag("Player").GetComponent<CubeController>(); }