Search Unity

Scripting a Sequence of Events

Discussion in 'Scripting' started by faultymoose, May 31, 2011.

  1. faultymoose

    faultymoose

    Joined:
    Oct 1, 2010
    Posts:
    246
    Situation:

    I have a player object which can enter a Portal, and be immediately teleported to a new location. Currently, this happens instantly. The Portal object, in it's OnTriggerEnter() function, calls the Player's Teleport() function to immediately send the player to the target location.

    Problem:

    What I would like to implement, is the following sequence of events when the player enters a Portal:

    1. The player controls stop responding and the player's avatar stops moving.
    2. The screen fades to black.
    3. The player's avatar is teleported to the new location.
    4. The screen fades up from black.

    Because this sequence of events relies on controlling numerous entities, I'm not sure how best to go about it, and was hoping someone might be able to propose some elegant solutions. I don't need code, rather I need help with organising my code.

    For example, the most 'brute force' (and messy) method I can think of would simply be to have a BeginTeleport() / EndTeleport() function on the Player, which in turn calls a Camera.FadeToBlack(), Player.TeleportToLocation(), Camera.FadeFromBlack() sequence of functions with callbacks to delay each step until the previous has been completed. This seems to me like it'd be bad practice, as I'd end up with this sequenced event split up across many different objects and scripts. Plus it confuses me just typing it ><

    Perhaps I could have a 'helper' object of some kind, which I simply call ActivateTeleport() on, and IT worries about moving the player, fading the camera, and handling the delays? Or is there another solution?

    Any help at all would be welcome, as I'm very new to Unity and I'm still getting used to how things work. Thankyou!
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
  3. faultymoose

    faultymoose

    Joined:
    Oct 1, 2010
    Posts:
    246
    Brilliant! Thankyou!