37 lines
1006 B
C#
37 lines
1006 B
C#
using UnityEngine;
|
||
//============================================================
|
||
//支持中文,文件使用UTF-8编码
|
||
//@author Adam
|
||
//@create 20221005
|
||
//@company Umawerse
|
||
//
|
||
//@description:
|
||
//============================================================
|
||
|
||
public class DistanceAdjuster : MonoBehaviour
|
||
{
|
||
public float minDistance = 100;
|
||
public float maxDistance = 300;
|
||
public float minScale = 1;
|
||
public float maxScale = 1;
|
||
private Camera _camera;
|
||
// Use this for initialization
|
||
private void Start () {
|
||
_camera = Camera.main;
|
||
}
|
||
|
||
private void Update()
|
||
{
|
||
var d = Vector3.Distance(transform.position, _camera.transform.position);
|
||
var s = Remap(d, minDistance, maxDistance, minScale, maxScale);
|
||
s= Mathf.Max(s, minScale);
|
||
s= Mathf.Min(s, maxScale);
|
||
transform.localScale = Vector3.one * s;
|
||
}
|
||
|
||
private float Remap(float value, float inMin, float inMax, float outMin, float outMax)
|
||
{
|
||
return (value - inMin) / (inMax - inMin) * (outMax - outMin) + outMin;
|
||
}
|
||
}
|