public void Update() { if (focus != null) { rg2d.velocity = ((focus.transform.position + Vector3.up * 3.5f) - transform.position).normalized * vel; if (Vector3.Distance(transform.position, focus.transform.position) < 4.0f) { missionTime += Time.deltaTime; textMission.text = $"{Mathf.RoundToInt((missionTime / 10.0f) * 100.0f)}%"; transform.position = focus.transform.position + Vector3.up * 3.5f; rg2d.velocity = Vector3.zero; if (missionTime >= 10.0f) { focus.GetComponent <Rotate>()?.ET_TP(); focus = null; } } } else { textMission.text = ""; rg2d.velocity = (startPoint - transform.position).normalized * vel; if (Vector3.Distance(startPoint, transform.position) < 10.0f) { Destroy(gameObject); } } }
public void SpawnMoon(Planete planete) { GameObject goMoon = Instantiate(MoonPrefab[Random.Range(0, MoonPrefab.Count)]); Rotate rotMoon = goMoon.GetComponent <Rotate>(); rotMoon.targetToRotate = planete.transform; rotMoon.worldPointToRotate = planete.GetComponent <Rotate>().worldPointToRotate; rotMoon.rotate = Vector2.one; rotMoon.rotateSpeed = 90.0f; Planete pMoon = goMoon.GetComponent <Planete>(); pMoon.isMoon = true; pMoon.planete = planete; }