コード例 #1
0
ファイル: Marble.cs プロジェクト: sunworld23/Unityballs
    // Respawn - Respawns the marble to roughly its starting position.
    public void Respawn()
    {
        Vector3 respawnOffset = new Vector3(0, 3, 0);

        ForceBrake();
        ResetState();

        if (gm.checkpoint)
        {
            marform.position = gm.checkpoint.position + respawnOffset;

            // Rotates camera to match checkpoint's rotation.
            ICamera camScript = cam.GetComponent <ICamera>();
            camScript.ResetPosition();                  // Makes sure camera is in right location.
            camScript.Freeze(true);                     // Prevents it from updating while changes are made.

            // Rotates it to face the direction of the checkpoint.
            cam.RotateAround(marform.position, Vector3.up, -Vector3.Angle(gm.checkpoint.forward,
                                                                          Vector3.Scale(cam.forward, new Vector3(1, 0, 1))));

            camScript.RecalculatePosition();                    // Forces it to update to new position.
            camScript.Freeze(false);                            // Unlocks.
        }
        else if (gm.respawn)
        {
            marform.position = gm.respawn.transform.position + respawnOffset;
        }
        else
        {
            Debug.LogWarning("(Marble.cs) No spawn point available! Placing in default location...");             // DEBUG
            marform.position = respawnOffset;
        }

        if (respawn != null)
        {
            respawn();
        }
    }