-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMovement.cs
62 lines (53 loc) · 1.75 KB
/
Movement.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
55
56
57
58
59
60
61
62
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Movement : MonoBehaviour {
public Camera cam;
//public Slider slider;
float maxWidth;
private bool reverse;
public bool can;
Vector3 bounds;
// Use this for initialization
void Start () {
bounds = new Vector3(Screen.width, 0.0f, 0.0f);
// SliderPos = cam.ScreenToWorldPoint(bounds);
can = false;
reverse = false;
if(cam == null)
{
cam = Camera.main;
}
Vector3 edge = new Vector3(Screen.width,Screen.height,0.0f);
Vector3 target = cam.ScreenToWorldPoint(edge);
float hoopWidth = (GetComponent<Renderer>().bounds.extents.x) / 2f;
maxWidth = target.x - hoopWidth;
}
void FixedUpdate()
{
if (can)
{
Vector3 newPosition;
Vector3 rawPosition = cam.ScreenToWorldPoint(Input.mousePosition);
// Vector3 rawPosition = new Vector3(slider.value * SliderPos.x, transform.position.y);
if (reverse)
{
newPosition = new Vector3(-rawPosition.x, transform.position.y, 0.0f);
}
else
{
newPosition = new Vector3(rawPosition.x, transform.position.y, 0.0f);
}
float target = Mathf.Clamp(newPosition.x, -maxWidth, maxWidth);
transform.position = Vector3.Lerp(transform.position,new Vector3(target, transform.position.y, 0.0f),Time.fixedDeltaTime * 7.5f);
}
}
public void toogle(bool other)
{
can = other;
}
public void Reversing(bool other)
{
reverse = other;
}
}