Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Help with room transition

Discussion in 'Scripting' started by cags099, Jan 16, 2021.

  1. cags099

    cags099

    Joined:
    Jan 16, 2021
    Posts:
    6
    I'm following Mister Taft Creates Overworld tutorial, right now at video number 8. The first room I made is 16x16 and the second one is 50x50. When trying to change rooms nothing happens, the character enters to the second area but camera does not move along.

    Ps: Box Collider 2D has already active the option of "Is Trigger"


    Here is the script:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class RoomMove : MonoBehaviour {

    public Vector2 cameraChangeMax;
    public Vector2 cameraChangeMin;
    public Vector3 playerChange;
    private CameraMovement cam;

    // Start is called before the first frame update
    void Start() {
    cam = Camera.main.GetComponent<CameraMovement>();
    }

    // Update is called once per frame
    void Update() {

    }

    private void OnTriggerEnter2D(Collider2D other)
    {
    if(other.CompareTag("Player"))
    {
    cam.minPosition.x = cameraChangeMin.x;
    cam.maxPosition.y = cameraChangeMin.y;
    cam.maxPosition.x = cameraChangeMax.x;
    cam.maxPosition.y = cameraChangeMax.y;
    other.transform.position += playerChange;
    }
    }
    }
     
  2. cags099

    cags099

    Joined:
    Jan 16, 2021
    Posts:
    6
    It was easy... player was not tagged as player...
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    cags099 likes this.