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
0
Question by sanks007 · Aug 30, 2013 at 02:59 PM · cameradragscroll

Camera Drag Script not working as expected.

Here us the link of what am trying to achieve. Now the question that i am posting now is related to the scrolling of the upper section.Lets say we have around 30 planes in the upper section. and around 10-15 are loaded when the application start.Now as user swipe across the background new planes are generated and background is scaled along its X-axis.Now what i need is as i scroll and when around 30 elements are generated i want the scroll to stop there so that it doesn't go any further i.e showing the last plane on either side.Here is the link on this basis i have done my script.I created borders on either side and attached the second script to it,but don't know why its still scrolling.Pasting the script out here for the reference. I think the issue may be with the camera thing. But If anyone would point out if there are mistake somewhere else as well.Here is the ScrollElementScript and this script is attached to the secondary camera.:

 #pragma strict
 
 var canMoveLeft: boolean = true;
 
 private var dragSpeed: float = 0.05;
 
 public var background:GameObject;
 var dragCamera : Camera;
 var startposition: Vector3;
 var nextposition: Vector3;
 var element:GameObject;
 var count:int;
 var testtext2:GameObject;
 var testtext3:GameObject;
 var Element: List.<GameObject>;
 var rightborder:GameObject;
 var canMoveRight: boolean = true;
 
 function Start()
 {
     testtext3=GameObject.Find("TestText3");
     testtext2=GameObject.Find("TestText2");
     startposition=Vector3(31.36466,16.36855,15.13743);
     Element.Capacity=20    ;
 }
 function Update () 
 {
     testtext3.GetComponent(TextMesh).text="Start Count::: "+count.ToString();
     var ray = dragCamera.ScreenPointToRay(Input.mousePosition);
     var hit : RaycastHit;
     if (Physics.Raycast (ray, hit)) 
     {
         if(hit.collider==background.collider)
         {
             if(Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Moved)
             {
                 if(Input.GetTouch(0).deltaPosition.x < 0 && canMoveRight || Input.GetTouch(0).deltaPosition.x > 0 && canMoveLeft)
                 {
                     if(Element.Count<21)
                     {
                         dragCamera.transform.position.x -= Input.GetTouch(0).deltaPosition.x * dragSpeed;
                         
                         nextposition=startposition;
                         nextposition.x=startposition.x+4;
                         startposition=nextposition;
                         
                         background.transform.localScale.x=background.transform.localScale.x+3.0;
                         testtext2.GetComponent(TextMesh).text="Updated Count::: "+Element.Count.ToString();
 
                         var go : GameObject = Instantiate ( element,nextposition,Quaternion.identity ); //no need for Resources.Load
                         Element.Add(go);
                         if(Element.Count==20)
                         {
                             rightborder=GameObject.Find("TopRightBorder");
                             rightborder.transform.position=nextposition;
                         }
                     }
                 }
             }    
         }
     }
 }
 
 function RestrictMove(dir: String)
 {
     if(dir == "left")  canMoveLeft = false;    
     if(dir == "right")  canMoveRight = false;        
 
 }
 
 function UnRestrictMove(dir: String)
 {
     if(dir == "left")  canMoveLeft = true;    
     if(dir == "right")  canMoveRight = true;        
 }
 

Now the second script which are attached to the borders is EdgeScript and it goes like this:

 #pragma strict
 
 var borderType: String = "top";
 var dragCamera : Camera;
 
 function OnBecameInvisible()
 {
     (dragCamera.gameObject.GetComponent("ScrollElementsScript") as ScrollElementsScript).UnRestrictMove(borderType);
 }
 
 function OnBecameVisible()
 {
     (dragCamera.gameObject.GetComponent("ScrollElementsScript") as ScrollElementsScript).RestrictMove(borderType);    
 }

I tried this procedure for other case and it worked perfectly.So where there can be an issue.

EDIT New observation that I encountered during further examination and testing.. Can scaling background might be another reason for it. ? The elements that are added are perfect 20 according to the condition. But its just the scroll that is not proper. Despite the part for Drag of camera being inside the condition it still moves even after satisfying the condition. And one more thing just out of curiosity while evaluating the condition just put the count of elements on the 3D Text to find if the condition gets satisfied. As I was scrolling 20 elements are created even if I scrolled very little why is this so.I understand update method is called every frame and many times per second so it has to be with it. So is there any way of controlling this behaviour ?

Comment
Add comment · Show 1
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 sanks007 · Sep 02, 2013 at 07:42 AM 0
Share

Come On Guys no answers for two days ... thats strange.!

0 Replies

· Add your reply
  • Sort: 

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

Can you use UI Scroll Rect for camera movement? 1 Answer

NGUI: Draggable Camera and Scroll Panel 0 Answers

The solution with camera rotation which is used in most strategic games 1 Answer

Rotating camera with RMB drag 1 Answer

How to have Camera following a Target, but not directly centered? 3 Answers


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