#Help
1 messages · Page 1 of 1 (latest)
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
So in short
I want the camera to stop when it gets to the end of the screen (set by me), above is the code, but it doesn't work
video in a sec
wait i will have a look
sorry but this makes no sense
so there are a few problems:
- the camera doesnt even have an collider so OnCollsion Events can't be triggered
- the bounds collider is set to trigger so that won't cause the Collision Event either even if the camera had an collider
i would recommend to use cinemachine for your camera system
Create the perfect 2D camera in Unity. Cinemachine gives you AAA quality camera controls within seconds. Creating your own camera script, although a viable option, can be very time-consuming and unless your camera controls require something completely unique, Cinemachine will give you what you need.
=========
❤️ Become a Tarobro on Patreon: ht...
here is an good and short tutorial
after that you can create an empty gameobject attach your old movement script to it and set the cinemachine target to that gameobject
and also remove the collision part since cinemachine does boundaries and the rest
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraMovement : MonoBehaviour
{
public float mDelta = 10; // Pixels. The width border at the edge in which the movement work
public float mSpeed = 3.0f; // Scale. Speed of the movement
private Vector3 mForwardDirection; // What direction does our camera start looking at
private Vector3 mRightDirection; // The inital "right" of the camera
//private Vector3 mUpDirection : float mSpeed { get => mSpeed; set => mSpeed = value; }
//Vector3; // The inital "up" of the camera
void Start()
{
mForwardDirection = transform.forward;
mRightDirection = transform.right;
//mUpDirection = transform.up;
}
void Update()
{
// Check if on the right edge
if (Input.mousePosition.x >= Screen.width - mDelta)
{
// Move the camera
transform.position += mRightDirection * Time.deltaTime * mSpeed;
}
if (Input.mousePosition.x <= 0 + mDelta)
{
// Move the camera
transform.position -= mRightDirection * Time.deltaTime * mSpeed;
}
Debug.Log(isTouching);
}
}