Search Unity

Question Cannot Set Boundaries in the Map

Discussion in 'Scripting' started by coysterry, Feb 22, 2024.

  1. coysterry

    coysterry

    Joined:
    Jan 14, 2024
    Posts:
    5
    Hi, I am trying to set up the boundaries on the map where my character moves, but after I insert these code in, my character still moves out of the boundary. Could you help me with this? Thanks

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    5.  
    6. public class Map : MonoBehaviour
    7. {
    8.     private BoundsInt boundsInt;
    9.     public Vector3Int MinAxis = new Vector3Int (0, 0, 0);
    10.     public Vector3Int MaxAxis = new Vector3Int (727, 405, 0);
    11.  
    12.     void Start()
    13.     {
    14.         boundsInt.SetMinMax(MinAxis, MaxAxis);
    15.     }
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,813
    Can you include the code that's meant to prevent the character from going outside the map bounds?
     
  3. coysterry

    coysterry

    Joined:
    Jan 14, 2024
    Posts:
    5
    Thanks for the tip. Didn't know I need this one as a beginner.