Search Unity

Question upscale cameramask before destroy

Discussion in '2D' started by nuketheduke, Oct 31, 2022.

  1. nuketheduke

    nuketheduke

    Joined:
    Feb 11, 2022
    Posts:
    4
    Hi all.

    I have been working with unity and c# for 4 month, and working on my first game.

    Now i have this problem : In start of level 5 there is a mask sprite as child of the camera, to make the view field smaller.
    I have a collider on a emty game object, that should scale up the spritemask to a
    specific size, before destroying the cameramask.
    It is to get the effect, that the fog slowly is disapering.
    My script is on the collider that should tricker it. So when the player passes through the collider, the script kicks in.
    When the script is attached to the collider, it scales up the collider. How can i make a refference, so it is the cameramask, that scales up instead ?.
    Hope someone have an idea.

    Code (csharp):
    1.  
    2. {
    3.     public GameObject cammask;
    4.    
    5.     private void OnTriggerEnter2D(Collider2D collision)
    6.     {
    7.         if (collision.gameObject.CompareTag("Player"))
    8.             {
    9.             Destroy(cammask);
    10.         }
    11.         // I have been trying with this code  
    12.         //transform.localScale = transform.localScale + new Vector3(1 * Time.deltaTime, 0, 0);
    13.     }
    14. }
    15.