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

C# script to change the position from one plane to another plane (make the background flashing)

Discussion in 'Scripting' started by pewpewpepper, Nov 26, 2014.

  1. pewpewpepper

    pewpewpepper

    Joined:
    Nov 26, 2014
    Posts:
    1
    My game is supposed to change from background1 (plane) to background2 and then go back to background1 (it looks like flashing) before the game scene ends.
    How should I make the script for doing that?
    Thanks in advance :)
     
  2. fox4snce

    fox4snce

    Joined:
    Jan 25, 2014
    Posts:
    74
    There are so many ways to do this it's kind of hard to choose just one.

    A really grungy way to do it is put one background in front of the other. So you have front and back.
    Now, disable the front, then reenable it.

    I think the code is gameObject.SetActive(false) to disable (this is in c#) and use SetActive(true) to enable.

    Something like...

    public GameObject front;
    public GameObject back;

    public void FlashBackground()
    {
    front.gameObject.SetActive(false);
    //(some kind of delay)
    front.gameObject.SetActive(true);
    }

    Another way would simply change the texture back and forth on a single object.

    If you aren't literally showing an image, you just want some kind of flashing effect... I'd look into some other method.