plantilla base para movimiento básico
This commit is contained in:
Robii Aragon
2026-02-05 05:07:55 -08:00
parent ed7b223c04
commit fd87a6ffd5
14441 changed files with 13711084 additions and 20 deletions

View File

@@ -0,0 +1,40 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class solarSystem : MonoBehaviour
{
public GameObject sun;
public float speed;
public bool useDistance;
public List<GameObject> planets = new List<GameObject> ();
//a script to make a simple solar system, where every planet rotates according to the distance to the sun
void Start ()
{
Component[] components = GetComponentsInChildren (typeof(Transform));
//get all the planets inside the solar system
foreach (Component c in components) {
if (c.CompareTag ("moving")) {
planets.Add (c.gameObject);
}
}
}
void Update ()
{
int planetsCount = planets.Count;
Vector3 sunPosition = sun.transform.position;
for (int i = 0; i < planets.Count; i++) {
float distance = GKC_Utils.distance (sunPosition, planets [i].transform.position);
if (useDistance) {
planets [i].transform.RotateAround (sunPosition, planets [i].transform.up, (speed / (distance / 20)) * Time.deltaTime);
} else {
planets [i].transform.RotateAround (sunPosition, planets [i].transform.up, speed * Time.deltaTime);
}
}
}
}