Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Add Paper To BookPro dynamically
using UnityEngine;
using System.Collections;
public class AddDynamicPages : MonoBehaviour {
public GameObject FrontPagePrefab;
public GameObject BackPagePrefab;
// Use this for initialization
void Start () {
public void AddPaper(BookPro book)
GameObject frontPage = Instantiate(FrontPagePrefab);
GameObject backPage = Instantiate(BackPagePrefab);
backPage.transform.SetParent(book.transform, false);
Paper newPaper = new Paper();
newPaper.Front = frontPage;
newPaper.Back = backPage;
Paper[] papers = new Paper[book.papers.Length + 1];
for(int i=0;i< book.papers.Length;i++)
papers[i] = book.papers[i];
papers[papers.Length-1] = newPaper;
book.papers = papers;
//update the flipping range to contain the new added paper
book.EndFlippingPaper = book.papers.Length - 1;
// Update is called once per frame
void Update () {

This comment has been minimized.

Copy link

@aloksonu aloksonu commented Jan 30, 2018

sir please explain how to use this script .....


This comment has been minimized.

Copy link
Owner Author

@Dandarawy Dandarawy commented Feb 3, 2018

1)-Create a new gameobject in the scene and attach the script on it
2)-Create a prefab for the front and back pages (should be similar to the the page object that is created by the editor and i.e. has the same components)
3)-Assign the front and back prefabs to this component
4)Call the function AddPaper when you want to add a new paper in the book
5)you may need to customize this function to add a paper in specific position in the book or to change some parts of the front and back prefabs dynamically

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment