Book opens before click and drag

Hello there

I´ve created a book that i want to give the user the possibility to click and drag each page. The problem is that my book opens when i move around no matter where i am in the scene because it responds to the mouse movement. I want the book to stay closed before the user gets near it and only opens it when he clicks and drags.

Here´s my code:

public class MegaBook : MonoBehaviour
{
	public GameObject		front;
	public GameObject		back;
	public GameObject		page1;
	public GameObject		page2;
	public GameObject		page3;
	public List<Texture>	pages = new List<Texture>();
	public float			bookalpha;
	public float			covergap = 0.0f;
	public float			pagespace = 0.01f;
	public float            dragsensi = 1.0f;
    public float            keysensi = 1.0f;
	

	MegaPageFlip			pf1;
	MegaPageFlip			pf2;
	MegaPageFlip			pf3;
	MeshRenderer			mrpg1;
	MeshRenderer			mrpg2;
	MeshRenderer			mrpg3;

	void SetPageTexture(MeshRenderer mr, int i, Texture t)
	{
		if ( mr.sharedMaterials*.mainTexture != t )*

_ mr.sharedMaterials*.mainTexture = t;_
_
}*_

* void Update()*
* {*
_ bookalpha += Input.GetAxis(“Mouse X”) * dragsensi;_
bookalpha = Mathf.Clamp(bookalpha, 0.0f, 100.0f);
This is just a bit of the code i`ve made. I did tried to use GetMouseButton instead of GetAxis but then i got this error from this line of code:
bookalpha += Input.GetMouseButton(0) * dragsensi;
operator * cannot be applied to operands of type ‘bool’ and float’
What am i missing here?

Yes, GetMouseButton returns true or false, to let you know if mouse is pressed or not… you can’t do true*dragsensi

You need some code that activates the book depending on how far the player is… here is something to get you started. Insert your code to switch pages on click to see if it works, later you can implement the dragging which isn’t that easy if you actually want to be able to click on the page and drag it to the side etc…

public float activateDistance = 1.5f; // Book activates if player is closer than 1.5m
public float deactivateDistance = 3f; // Book deactivates again if Player walks away more than 3m
public Transform player; // drag the player into this

private bool bookActive = false;

void Update()
{
  // activating and deactivating Book
  if (!bookActive)
  {
    if ((transform.position-player.position).magnitude<activateDistance)
    {
      bookActive = true;
      // also activate a particle system here, that lets the book magically glow
      // and lets the player know that the book is active :)
    }
  } else {
    if ((transform.position-player.position).magnitude>deactivateDistance)
    {
      bookActive = false;
      // also deactivate the particle system here if you have one :D
    }
  }

  // handle book logic
  if (bookActive)
  {
    if(Input.GetMouseButtonDown(0)) // mouse button was just pressed
    {
      // do whatever you have to do to show the next page
    }
  }

  
}