Hello,
I have two scripts, I want to recycle platform and I used OnBecameInvisible, but when the first platforms became invisible, all platform get wrong position. What is the problem? Thanks in advance!
public class Platform_Recycle : MonoBehaviour
{
private Platform_Manager _platformManager;
private void Awake()
{
_platformManager = GameObject.FindObjectOfType<Platform_Manager>();
}
private void OnBecameInvisible()
{
_platformManager.Recycle_Platform(this.gameObject);
}
}
public class Platform_Manager : MonoBehaviour
{
[SerializeField] private GameObject[] platforms;
private float _offSet;
void Start()
{
for(int i = 0; i < platforms.Length; i++)
{
Instantiate(platforms_, new Vector3(0f, 0f, i * 80.499f), Quaternion.Euler(0f, 0f, 0f));_
_offSet = _offSet + 80.499f;
}
}
public void Recycle_Platform(GameObject platform)
{
platform.transform.position = new Vector3(0f, 0f, _offSet);
_offSet = _offSet + 80.499f;
print(_offSet);
}
}
[178557-capture.png|178557]*
*