Search Unity

My Camera follow script doesn't work when reloading my project or in a build version of my game

Discussion in 'Scripting' started by technano, Apr 26, 2020.

  1. technano

    technano

    Joined:
    Jan 13, 2016
    Posts:
    23
    So I have a script that follows the player and it works but when first starting up my project or building it as a standalone application it won't follow the player at all. It always says that the components are in the fields in the inspector when i first look at the game object. I always have to remove the script from the game object and add it back and re add the components like the target and everything!

    I don't really even know where to start in trying to fix this, so i'm really feeling lost at the moment! :(

    If you guys need any other kind of files please let me know what I can give to help figure this out! Thank you!
     

    Attached Files:

  2. Cannist

    Cannist

    Joined:
    Mar 31, 2020
    Posts:
    64
    I'm quite new to Unity and C# myself, but what looks suspicious to me is that you assign
    singleton = this
    in
    Awake()
    . That means nothing prevents you from creating multiple
    CameraHandler
    s and only the latest one will be referenced by the
    singleton 
    field. You probably either don't need a singleton at all or you want to make sure that really only one instance of your class exists (which might mean that it should not be a MonoBehaviour but a separate class that only gets referenced and used by a MonoBehaviour.)