43 lines
1.1 KiB
C#
43 lines
1.1 KiB
C#
|
using UnityEngine;
|
|||
|
using System.Collections.Generic;
|
|||
|
|
|||
|
public class MaintainBallScale : MonoBehaviour
|
|||
|
{
|
|||
|
[System.Serializable]
|
|||
|
public class BallData
|
|||
|
{
|
|||
|
public Transform ball;
|
|||
|
[HideInInspector]
|
|||
|
public Vector3 initialWorldScale;
|
|||
|
}
|
|||
|
|
|||
|
public List<BallData> balls = new List<BallData>();
|
|||
|
|
|||
|
void Start()
|
|||
|
{
|
|||
|
foreach (var ballData in balls)
|
|||
|
{
|
|||
|
if (ballData.ball != null)
|
|||
|
{
|
|||
|
ballData.initialWorldScale = ballData.ball.lossyScale;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void LateUpdate()
|
|||
|
{
|
|||
|
foreach (var ballData in balls)
|
|||
|
{
|
|||
|
if (ballData.ball != null && ballData.ball.parent != null)
|
|||
|
{
|
|||
|
Vector3 parentScale = ballData.ball.parent.lossyScale;
|
|||
|
ballData.ball.localScale = new Vector3(
|
|||
|
ballData.initialWorldScale.x / parentScale.x,
|
|||
|
ballData.initialWorldScale.y / parentScale.y,
|
|||
|
ballData.initialWorldScale.z / parentScale.z
|
|||
|
);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|