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

Script not working after build

Discussion in 'Editor & General Support' started by orlyx, May 15, 2019.

  1. orlyx

    orlyx

    Joined:
    Feb 21, 2019
    Posts:
    2
    I for the first time build my project, but main room transfer script is not working. I found many posts about almost the same problem but after trying almost everything that was in these posts its still not working.
    C# script:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class RoomMove : MonoBehaviour
    6. {
    7.     public Vector2 maxChange;
    8.     public Vector2 minChange;
    9.     public Vector3 playerChange;
    10.     private CameraMovement cam;
    11.     // Start is called before the first frame update
    12.     void Start()
    13.     {
    14.         cam = Camera.main.GetComponent<CameraMovement>();
    15.     }
    16.  
    17.     // Update is called once per frame
    18.     void Update()
    19.     {
    20.      
    21.     }
    22.  
    23.     private void OnTriggerEnter2D(Collider2D other)
    24.     {
    25.         if(other.CompareTag("player"))
    26.         {
    27.             cam.minPosition = maxChange;
    28.             cam.maxPosition = minChange;
    29.             other.transform.position = playerChange;
    30.         }
    31.     }
    32. }
    C# camera script:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class CameraMovement : MonoBehaviour
    6. {
    7.     public Transform target;
    8.     public float smoothing;
    9.  
    10.     public Vector2 maxPosition;
    11.     public Vector2 minPosition;
    12.  
    13.     // Start is called before the first frame update
    14.     void Start()
    15.     {
    16.      
    17.     }
    18.  
    19.     // Update is called once per frame
    20.     void LateUpdate()
    21.     {
    22.         if(transform.position != target.position)
    23.         {
    24.             Vector3 targetPosition = new Vector3(target.position.x, target.position.y, transform.position.z);
    25.             targetPosition.x = Mathf.Clamp(target.position.x, minPosition.x, maxPosition.x);
    26.             targetPosition.y = Mathf.Clamp(target.position.y, minPosition.y, maxPosition.y);
    27.             transform.position = Vector3.Lerp(transform.position, targetPosition, smoothing);
    28.         }
    29.     }
    30. }
    Screens that sholud help:
    upload_2019-5-15_16-5-19.png

    after "Reimporting All" this came up but before there wasnt any problems.
    upload_2019-5-15_16-5-0.png