- Home /
 
               Question by 
               noemykiki · Sep 17, 2021 at 12:10 PM · 
                c#clampcamera script  
              
 
              Camera bounds script not working
Hi, so I have a camera in a scene that follows the player around, however my camera bounds/border script is no longer functioning. I'm not sure If I perhaps typed something wrong, I don't get any errors or anything, but it is not clamping on the positions that I set.
Here is the camera follow script:
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class CameraFollow2D : MonoBehaviour
 {
     
     [SerializeField]
     GameObject player;
 
     void LateUpdate()
     {
         if (player == null)
         {
             PlayerMovement playerMovement = FindObjectOfType<PlayerMovement>();
             if (playerMovement != null)
                 player = playerMovement.gameObject;
         }
         transform.position = new Vector3(player.transform.position.x, player.transform.position.y, -10);
     }
 
 
 }
 
 
 
 
And here is the camera border script:
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 [DisallowMultipleComponent]
 public class CameraBorder : MonoBehaviour
 {
     [SerializeField]
     float leftLimit;
     [SerializeField]
     float rightLimit;
     [SerializeField]
     float bottomLimit;
     [SerializeField]
     float topLimit; 
 
     void Update()
     {
         transform.position = new Vector3
         (
             Mathf.Clamp(transform.position.x, leftLimit, rightLimit),
             Mathf.Clamp(transform.position.y, bottomLimit, topLimit),
             transform.position.z
 
         );
     }
 }
 
     
 
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Camera follow Player Script - Problem 1 Answer
Slide object between two moving points c# 1 Answer
Camera global rotation clamping issue 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
               
 
			 
                