Hi
I’ve tried numerous attempts at getting this problem corrected, but am hitting a wall for a solution.
I have a list of icons that the user can scroll up and down to view. This side of it works well. However, I need to put ‘stoppers’ on the top and bottom of the list so that obviously the user can’t scroll beyond the start and end of the list.
I tried to insert mathf.clamp into my code, but so far no luck… I know I’m doing something wrong somewhere, or don’t understand mathf.clamp enough to know how to implement it correctly.
I’ve also tried placing a trigger and rigidbody on the control object for the list, with trigger box boundaries top and bottom, but couldn’t get it working that way, either.
Any suggestions or advice would be greatly appreciated.
Here’s the code I use to move the list:
function Start(){
directionY = Vector3(0,1,0);
directionYDown = Vector3(0,-1,0);
}
function FixedUpdate() {
for (var touch : Touch in Input.touches) {
if(Input.touchCount == 1) {
if (Input.GetTouch(0).phase == TouchPhase.Moved) {
ChangeInX = Input.touches[0].deltaPosition.x * Time.deltaTime;
ChangeInY = Input.touches[0].deltaPosition.y * Time.deltaTime;
if (Mathf.Abs(ChangeInX) < Mathf.Abs(ChangeInY)){
MoveY();
break;
}
}
}
}
}
function MoveY() {
if (ChangeInY > 0) {
GoUp();
return;
}
if (ChangeInY < 0) {
GoDown();
return;
}
}
function GoUp() {
objectToMove.transform.Translate (directionY * Time.deltaTime*objectSpeed, Space.World);
}
function GoDown() {
objectToMove.transform.Translate (directionYDown * Time.deltaTime*objectSpeed, Space.World);
}