-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathScaleOnDistance.cs
More file actions
42 lines (33 loc) · 1.06 KB
/
ScaleOnDistance.cs
File metadata and controls
42 lines (33 loc) · 1.06 KB
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ScaleOnDistance : MonoBehaviour
{
[Header("Settings")]
[SerializeField] private bool _Revert;
[SerializeField] private Vector2 _MinMaxSize;
[SerializeField] private Vector2 _MinMaxDistance;
[Header("Target")]
[SerializeField] private Transform _Target;
private Vector3 _DefaultScale;
void Start()
{
_DefaultScale = transform.localScale;
}
void Update()
{
//Calc
float a = (Vector3.Distance(transform.position, _Target.position) - _MinMaxDistance.x) * (1 / (_MinMaxDistance.y - _MinMaxDistance.x));
float b = _MinMaxSize.y - _MinMaxSize.x;
if (_Revert)
a = 1 - a;
float newsize = a * b;
//Limits
if (newsize < _MinMaxSize.x)
newsize = _MinMaxSize.x;
if (newsize > _MinMaxSize.y)
newsize = _MinMaxSize.y;
//Apply
transform.localScale = _DefaultScale * newsize;
}
}