using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MainGame : MonoBehaviour
{
public GameObject TargetObj;
public GameObject MoveObj;
private float StartDis;
void Start()
{
StartDis = CalculateDis();
}
void Update()
{
Near_little_far_bjg();
}
private void Near_little_far_bjg()
{
float dis = CalculateDis();
Debug.Log(dis);
if (dis >= StartDis)
{
float xyz = dis / StartDis;
MoveObj.transform.localScale = new Vector3(xyz, xyz, 1);
}
}
private float CalculateDis()
{
return Vector3.Distance(TargetObj.transform.position, MoveObj.transform.position);
}
}
|