-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreditMovement.cs
54 lines (38 loc) · 1.39 KB
/
CreditMovement.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CreditMovement : MonoBehaviour
{
public int BoundaryPercentage = 25;
public int Speed = 5;
public int TopBound;
public int BottomBound;
private int _bottomPanTrigger;
private int _topPanTrigger;
private int _totalPanRange;
// Start is called before the first frame update
void Start()
{
_bottomPanTrigger = (int)((BoundaryPercentage / 100.0) * Screen.height);
_topPanTrigger = Screen.height - _bottomPanTrigger;
_totalPanRange = _bottomPanTrigger;
}
// Update is called once per frame
void Update()
{
Pan();
}
public void Pan()
{
if (Input.mousePosition.y > _topPanTrigger && transform.position.y < TopBound) //move up
{
float speedMultiplier = (Input.mousePosition.y - _topPanTrigger) / _totalPanRange;
transform.Translate(Vector3.up * Time.deltaTime * Speed * speedMultiplier);
}
else if (Input.mousePosition.y < _bottomPanTrigger && transform.position.y > BottomBound) //move down
{
float speedMultiplier = (_totalPanRange - Input.mousePosition.y) / _totalPanRange;
transform.Translate(-Vector3.up * Time.deltaTime * Speed * speedMultiplier);
}
}
}