Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How do i detect when the player is touching the edge?

Discussion in 'Scripting' started by Bigmancozmo, Dec 12, 2020.

  1. Bigmancozmo

    Bigmancozmo

    Joined:
    Sep 13, 2020
    Posts:
    17
    Just so you know, my player is called "Hero," however it is also stored in a GameObject variable called "hero." So don't use the capitals when referencing my player.

    I need to check when the player is touching the edge of the screen. I just need some simple code.
    Thanks!
    -Bigmancozmo
     
  2. anglojojo

    anglojojo

    Joined:
    Nov 11, 2020
    Posts:
    18
    It really depends on the shape of your objects collider, but what do you mean the edge of the screen? for Camera control? or like walls and stuff?
     
  3. Bigmancozmo

    Bigmancozmo

    Joined:
    Sep 13, 2020
    Posts:
    17
    I want to make it so the player always stays in view on the screen. What i mean is that they can ALWAYS be seen in the main camera.
     
  4. anglojojo

    anglojojo

    Joined:
    Nov 11, 2020
    Posts:
    18
    Got ya, I am also new to Unity, but I've looked into this a bit already.
    There are various ways to achieve the same results, some require more coding some less, but its really specific to what style of Camera follow you are after. Which also depends on the type of game you are making.

    I suggest watching a various "follow player" tutorials on Youtube to see which method best fits your game.

    In the meantime to give you an easy solution, what you could do without even coding, is drag the "MainCamera" under the player's GameObject, then reset the Camera's position so its centered with the players position.

    This will follow your player without any scrips, hopefully this helps a fellow newwb lol