Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        Vector3 currentPos = transform.position;
        var     targetTile = new Rect(currentPos, Vector2.one);

        _building = GameObject.Find("Building Interior").GetComponent <BuildingInterior>();
        if (_building.IsExiting(targetTile))
        {
            SceneManager.LoadScene(SceneSettings.SceneIdForTerrainView);
        }
        if (_building.IsBlocked(targetTile))
        {
            transform.position = currentPos = _previousPosition;
        }
        _previousPosition = currentPos;
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        //walk or run
        var currentSpeed = speed;

        if (Input.GetKey(EnableFastSpeed))
        {
            currentSpeed = fastSpeed;
        }
        var movement = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0);

        transform.Translate(movement * currentSpeed * Time.deltaTime);

        //turn player icon
        if (movement.x > 0.1f || movement.x < -0.1f || movement.y > 0.1f || movement.y < -0.1f)
        {
            turnWithMovement.rotation = Quaternion.LookRotation(Vector3.back, movement.normalized);
        }

        //check if blocked tile
        Vector3 currentPos = transform.position;
        var     player     = new Rect(currentPos, Vector2.one);

        if (Building.IsBlocked(player))
        {
            transform.position = currentPos = previousPosition;
        }
        if (Building.IsExiting(player))
        {
            var go = new GameObject();
            GameObject.DontDestroyOnLoad(go);
            var starter = go.AddComponent <TerrainStarter>();
            starter.PreviousPosition = Building.PreviousPosition;
            SceneManager.LoadScene(Building.SceneIdForTerrainView);
        }
        previousPosition = currentPos;
    }