Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Trying to create an efficient world flipping system

Discussion in 'Scripting' started by Sophophilia_Studios, Nov 3, 2015.

  1. Sophophilia_Studios

    Sophophilia_Studios

    Joined:
    Jul 28, 2015
    Posts:
    21
    I am adding a world flip mechanic the a 2D Platforme.
    I am looking for an efficient way of creating the world flip system. Not the actual flip, as I think what I built already is pretty good (I flip the camera and reverse gravity on the RigidBody2D and rotation of the Player)
    But I am wondering what the best way to create a system in which a bunch of scripts can access a variable that tells them the world has flipped.
    Right now I just have bool that is called worldFlip and it is a static in a class called WorldFlipSystem.

    The PlatformerCharacter2D class needs to know if the world has flipped because I need to invert the m_JumpForce. But the way I am doing it is really inefficient because I just have it constantly looking to see if the WorldFlipSystem.worldFlip is True or false and then making the m_JumpForce negative or positive. But that is happening every frame. I want it to just do it once, right when the world flips.

    I thought the way to do this was to create a method in the WorldFlipSystem class but I don't know how to make other classes know if a method has been activated or now without creating an instance of all classes in the class that is doing the method. Hopefully there is an easier way.

    tldr; How do I create a system that has a switch, and allows any other class to see when that switch happens?

    Thanks
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,735
    What makes you think this is at all inefficient? Have you found issues profiling it?