Ejemplo n.º 1
0
    /// <summary>
    /// Creates the specified object for the player attached to this object
    /// </summary>
    /// <param name="prefab">The prefab to instantiate</param>
    /// <param name="position">The location at which to spawn the item</param>
    /// <param name="characterIndex">The index of the selected character</param>
    /// <param name="playerIndex">The index of the player</param>
    /// <param name="id">ID of the profile</param>
    /// <returns>The transform that was created</returns>
    public override Transform Spawn(Transform prefab, Vector3 position, int characterIndex, string playerName, int playerIndex, Guid id)
    {
        base.Spawn(prefab, position, characterIndex, playerName, playerIndex, id);

        // create the player display
        _player = Instantiate(prefab, position, Quaternion.identity);

        // set the height of the object
        SetHeight(_player, characterIndex);

        // use the correct animation controller
        SetAnimation(_player, characterIndex);

        // get the jump script
        _jumpScript = _player.GetComponent <PlayerJumper>();
        _jumpScript.SetCollisionCallback(CheckFinish_);

        // get the movement script - disable it to stop the animations getting in each others way
        _movement         = _player.GetComponent <PlayerMovement>();
        _movement.enabled = false;

        // set the layers
        _player.gameObject.layer = LayerMask.NameToLayer("Player" + (playerIndex + 1) + "A");
        _jumpScript.ColliderB.gameObject.layer = LayerMask.NameToLayer("Player" + (playerIndex + 1) + "C");

        // sprite renderer updates
        var sr = _player.GetComponent <SpriteRenderer>();

        sr.sortingLayerName = "Player" + (playerIndex + 1) + "B";
        sr.sortingOrder     = 1;
        sr.maskInteraction  = SpriteMaskInteraction.VisibleOutsideMask;

        return(_player);
    }
Ejemplo n.º 2
0
 void Start()
 {
     BodyPhysic   = gameObject.GetComponent <Rigidbody2D> ();
     Way          = gameObject.GetComponent <Trajectory> ();
     CountManager = Count.GetComponent <Counters> ();
     Particle     = GetComponent <PlayerParticle> ();
     Jumper       = GetComponent <PlayerJumper> ();
     StartCoroutine(Jumper.Play(Grounded, BodyPhysic));
 }