using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[ExecuteInEditMode]
public class StarBehavior : MonoBehaviour {

	[SerializeField] Transform player;
	Transform thisTF;

	void Start ()
	{
		thisTF = GetComponent<Transform> ();
	}

	void Update () 
	{
		thisTF = GetComponent<Transform> ();

		if (player.position.x - thisTF.position.x > StarsInfo.size / 2) {
			thisTF.position += Vector3.right * StarsInfo.size;
		}
		if (player.position.x - thisTF.position.x < -StarsInfo.size / 2) {
			thisTF.position -= Vector3.right * StarsInfo.size;
		}

		if (player.position.y - thisTF.position.y > StarsInfo.size / 2) {
			thisTF.position += Vector3.up * StarsInfo.size;
		}
		if (player.position.y - thisTF.position.y < -StarsInfo.size / 2) {
			thisTF.position -= Vector3.up * StarsInfo.size;
		}

		if (player.position.z - thisTF.position.z > StarsInfo.size / 2) {
			thisTF.position += Vector3.forward * StarsInfo.size;
		}
		if (player.position.z - thisTF.position.z < -StarsInfo.size / 2) {
			thisTF.position -= Vector3.forward * StarsInfo.size;
		}
	}

}
