Search Unity

Where to store reference to objects?

Discussion in 'Entity Component System' started by Deleted User, Jul 5, 2019.

  1. Deleted User

    Deleted User

    Guest

    I have a
    ComponentSystem
    that wants to perform raycast from camera.
    I don't want to use Camera.main inside
    OnUpdate
    . I want to cache the camera somewhere and use that.
    So what's the best way to do it? Should I use
    SystemStateComponent
    ?
     
  2. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,117
    Code (CSharp):
    1.  public class MyCameraSystem : ComponentSystem
    2.     {
    3.       Camera camera;
    4.         protected override void OnCreateManager()
    5.         {
    6.             camera = Camera.main; // reference here
    7.         }
    8.      
    9.  
    10.         protected override void OnUpdate( )
    11.         {
    12.           // use camera here
    13.          }
    14.    }
     
    Deleted User likes this.