void Start()
    {
        endPosition = transform.position;

        LeftWallScript  = LeftWallFeel.GetComponent <LeftWallDetect>();
        RightWallScript = RightWallFeel.GetComponent <RightWallDetect>();
        UpWallScript    = UpWallFeel.GetComponent <UpWallDetect>();
        DownWallScript  = DownWallFeel.GetComponent <DownWallDetect>();

        Box1 = Box.GetComponent <BoxMove>();
    }
예제 #2
0
    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;
            }
        }
    }