-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScaleButton.cs
45 lines (34 loc) · 972 Bytes
/
ScaleButton.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ScaleButton : MonoBehaviour
{
private bool isUsing;
public bool IsUsing { get => isUsing; set => isUsing = value; }
Transform objectToScale;
Vector2 lastMousePos;
private void OnMouseDown()
{
IsUsing = true;
}
private void OnMouseUp()
{
IsUsing = false;
}
private void Update()
{
if (IsUsing)
{
float mouseDifference = (Input.mousePosition.x - lastMousePos.x) * Time.deltaTime;
objectToScale.localScale = new Vector3(
Mathf.Clamp((objectToScale.localScale.x + mouseDifference), 0.1f, 2f),
objectToScale.localScale.y,
objectToScale.localScale.z);
lastMousePos = Input.mousePosition;
}
}
public void SetObjectToScale(Transform transform)
{
objectToScale = transform;
}
}