Search Unity

Making Camera a prefab in order to use it with UnityEvent

Discussion in 'Getting Started' started by default_team, Dec 7, 2018.

  1. default_team

    default_team

    Joined:
    Dec 1, 2018
    Posts:
    21
    In short, I want to change the camera's position OnPlayerDeath. I have a Player class that invokes a PlayerDeathEvent:

    Code (CSharp):
    1. class Player : MonoBehavior {
    2.     public UnityEvent PlayerDeathEvent;
    3.  
    4.     void OnPlayerDeath() {
    5.        PlayerDeathEvent.Invoke();
    6.    }
    7. }
    And a CameraMovement.cs that is attached to the Camera as a script component.

    Code (CSharp):
    1. class CameraMovement {
    2.   public void ChangePosition() {
    3.   }
    4. }
    As PlayerDeathEvent is public I could see it in the inspector. To call CameraMovement.MoveToPosition() on PlayerDeathEvent. I could do either:

    - Drag 'Main Camera' from Hierarchy view to the 'None (Object)' field in the inspector
    - Or create a prefab out of the camera, and drag that prefab to the 'None (Object)' field in the inspector



    I'm not sure, what is the right apprach to take. Any insights on this?
     
    Last edited: Dec 8, 2018