Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by LijuDeveloper · Nov 05, 2013 at 10:44 AM · meshmeshcolliderscrollviewscrollscrolling

Scroll view using Mesh

How to make a scroll view like GUI Scroll view GUI.BeginScrollView using mesh ?

For example in GUI Scroll view we can scroll the other GUI components. How to do same thing using thing to scroll other objects like plane, Quad ?

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Berenger · Nov 05, 2013 at 11:13 AM 0
Share

What do you mean ? A scroll view with game objects ?

avatar image LijuDeveloper · Nov 06, 2013 at 04:21 AM 0
Share

yes, scroll view with objects like plane , Quad etc..

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by LijuDeveloper · Nov 29, 2013 at 11:19 AM

I got solution .

Use This scripts in ScrollButton (Mesh)

Script

     using UnityEngine;
     using System.Collections;


    public class ScrollController : MonoBehaviour 

    {
 public GameObject       go_scrollContentObj;

 public Camera           scrollViewCam;

 private float           mouseXpos;

 private float           mouseYpos;

 private float           scrollPos ;

 public float           mouseScrollPos = -2.5f ;

 public  float           scrollViewSpeed = 3f;

 public  float            maxScrollHeight= 1.5f;

 public  float            minScrollHeight= -1.5f;
 
 
 private Vector3            screenPoint;

 private Vector3            offset;

 private Vector3            scrollScreenPoint;

 private Vector3            scrollOffset;
 
 
 
 
 private float           screenHeight;

 private float           screenWidth;

 
 private bool            boolMouseDrag;

 private bool            boolMouseDown;

 public Vector3             mousePosInScreen;

 void Start()
 {
     transform.position =new Vector3 (transform.position.x,maxScrollHeight - transform.position.x,transform.position.z);// scrollButtonStartPosition;
 }
 
 void OnMouseDown()
 {
     boolMouseDown  = true;  
     
     screenPoint = Camera.main.WorldToScreenPoint(transform.position );
     
     offset = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(screenPoint.x, Input.mousePosition.y, screenPoint.z));//new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
 }
 
 void Update()
 {
     screenHeight = Screen.height;
     screenWidth = Screen.width;
     
     
     mousePosInScreen =scrollViewCam.ScreenToViewportPoint(Input.mousePosition) ;


     if( transform.position .y >= maxScrollHeight )
     {
         transform.position = new Vector3 (transform.position.x,maxScrollHeight - 0.01f,transform.position.z);   
     }
     else if( transform.position .y <= minScrollHeight )
     {
         transform.position = new Vector3 (transform.position.x,minScrollHeight + 0.01f,transform.position.z);   
     }
     go_scrollContentObj.transform.position = new Vector3(go_scrollContentObj.transform.position.x,-transform.position.y * scrollViewSpeed ,go_scrollContentObj.transform.position.z);
     
     

     
     scrollPos = Mathf.Clamp (scrollPos, minScrollHeight  ,maxScrollHeight  );
     if( mousePosInScreen.x >= 0 &&  mousePosInScreen.x  <= 1 &&  mousePosInScreen.y >=0 &&  mousePosInScreen.y <= 1)
     {
         
         if(boolMouseDown == false && boolMouseDrag == false )
         {
             mouseScrollPos = transform.position.y;
             mouseScrollPos =mouseScrollPos + Input.GetAxis("Mouse ScrollWheel");
             mouseScrollPos = Mathf.Clamp (mouseScrollPos, minScrollHeight  ,maxScrollHeight  );
             transform.position = new Vector3 (transform.position.x ,mouseScrollPos ,transform.position.z);
         }
     }
     
     if(Input.GetMouseButtonUp(0))
     {
         boolMouseDown = false;
         boolMouseDrag =false;
         
     }
     
 }
 
 
      void OnMouseDrag()
      {
     boolMouseDrag = true;
     
     Vector3 curScreenPoint = new Vector3(screenPoint.x, Input.mousePosition.y, screenPoint.z);//
     Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
     transform.position = curPosition;

     }
 }

I developed this code from Crazydadz's idea

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Crazydadz · Nov 07, 2013 at 04:13 AM

A simple way is to use 3 planes. One fixed plane covering the top of the screen, one fixed plane covering the bottom of the screen and one in the middle. Place the middle one a little bit behind the 2 others. This plane will be the scrollable mesh. To scroll it, use an empty fixed gameobject with a collider on it with a script like so:

 public Transform ScrollingObject; // Put the middle plane in the inspector in here
 
 private void Update()
 {
     // Cast a raycast to detect if your mouse is over the empty fixed GameObject collider with Physics.Raycast and Camera.ScreenPointToRay(Input.mousePosition)
   
   _scrollPos += Input.GetAxis("Mouse ScrollWheel") * Speed;
 
   _scrollPos = Mathf.Clamp(_scrollPos, MinPositionToScroll, MaxPositionToScroll);
 
   ScrollingObject.position = new Vector3(0f, _scrollPos, ScrollingObject.position.z);
 
 }

That is just an idea. I wrote it on the fly. I know the idea is working because I used it recently in my last Game. Unfortunately, with this idea, you need to cover all the top and the bottom of the screen, ifnot you see the middle scrollable plane behind the top and bottom plan and it is ugly.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image LijuDeveloper · Nov 07, 2013 at 04:17 AM 0
Share

I will check , Thanks for help

avatar image Crazydadz · Nov 07, 2013 at 04:20 AM 1
Share

if you need more info to accomplish this, just ask. I ll answer you tomorrow at work.

avatar image LijuDeveloper · Nov 07, 2013 at 04:35 AM 0
Share

Thanks , its working.

avatar image Crazydadz · Nov 07, 2013 at 05:57 AM 1
Share

Ive done some search to avoid creating a scrollview covering all the screen. Check this. I can't test something right now but taking this idea with $$anonymous$$e can create more nice looking scrollview with meshes.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Scroll View: Is there a way to discriminate and accept only certain PointerEvents? 0 Answers

Unity scroll unknown length, runtime adding items 1 Answer

I am still able to scroll even though scroll type is clamped? 0 Answers

How to disable mouse wheel scroll inside a scrollview? 1 Answer

Scrollview is positioning things incorrectly 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges