void Update() { if (Input.GetKeyDown(KeyCode.R)) { Application.LoadLevel(Application.loadedLevel); } Box1 = Box.GetComponent <BoxMove>(); if (Input.GetKeyDown(KeyCode.A)) //left { if (LeftWallScript.leftHitWall()) { Debug.Log("Ran into Wall"); endPosition = new Vector3(endPosition.x, endPosition.y, endPosition.z); moveToPoint = true; } else { Debug.Log("Out OF Wall"); endPosition = new Vector3(endPosition.x - distanceToMove, endPosition.y, endPosition.z); moveToPoint = true; } } if (Input.GetKeyDown(KeyCode.D)) //Right { if (RightWallScript.rightHitWall()) { endPosition = new Vector3(endPosition.x, endPosition.y, endPosition.z); moveToPoint = true; } else { endPosition = new Vector3(endPosition.x + distanceToMove, endPosition.y, endPosition.z); moveToPoint = true; } } if (Input.GetKeyDown(KeyCode.W)) //Up { if (UpWallScript.upHitWall()) { //Debug.Log("Hit an Up Wall"); endPosition = new Vector3(endPosition.x, endPosition.y, endPosition.z); moveToPoint = true; } else { //Debug.Log("Out Of Up Wall"); endPosition = new Vector3(endPosition.x, endPosition.y + distanceToMove, endPosition.z); moveToPoint = true; } } if (Input.GetKeyDown(KeyCode.S)) //Down { if (DownWallScript.downHitWall()) { endPosition = new Vector3(endPosition.x, endPosition.y, endPosition.z); moveToPoint = true; } else { endPosition = new Vector3(endPosition.x, endPosition.y - distanceToMove, endPosition.z); moveToPoint = true; } } }
void Update() { LeftWallScript = LeftWall.GetComponent <LeftWallDetect>(); RightWallScript = RightWall.GetComponent <RightWallDetect>(); UpWallScript = UpWall.GetComponent <UpWallDetect>(); DownWallScript = DownWall.GetComponent <DownWallDetect>(); if (Input.GetKeyDown(KeyCode.A)) //left { if (LeftWallScript.leftHitWall()) { //Debug.Log("Ran into Wall"); endPosition = new Vector3(endPosition.x, endPosition.y, endPosition.z); moveToPoint = true; } else { //Debug.Log("Out OF Wall"); endPosition = new Vector3(endPosition.x - distanceToMove, endPosition.y, endPosition.z); moveToPoint = true; } } if (Input.GetKeyDown(KeyCode.D)) //Right { if (RightWallScript.rightHitWall()) { endPosition = new Vector3(endPosition.x, endPosition.y, endPosition.z); moveToPoint = true; } else { endPosition = new Vector3(endPosition.x + distanceToMove, endPosition.y, endPosition.z); moveToPoint = true; } } if (Input.GetKeyDown(KeyCode.W)) //Up { if (UpWallScript.upHitWall()) { Debug.Log("Hit an Up Wall"); endPosition = new Vector3(endPosition.x, endPosition.y, endPosition.z); moveToPoint = true; } else { Debug.Log("Out Of Up Wall"); endPosition = new Vector3(endPosition.x, endPosition.y + distanceToMove, endPosition.z); moveToPoint = true; } } if (Input.GetKeyDown(KeyCode.S)) //Down { if (DownWallScript.downHitWall()) { endPosition = new Vector3(endPosition.x, endPosition.y, endPosition.z); moveToPoint = true; } else { endPosition = new Vector3(endPosition.x, endPosition.y - distanceToMove, endPosition.z); moveToPoint = true; } } }