Files
FueraDeEscala/Assets/Game Kit Controller/Scripts/Demo/solarSystem.cs
Robii Aragon fd87a6ffd5 add ckg
plantilla base para movimiento básico
2026-02-05 05:07:55 -08:00

40 lines
1.1 KiB
C#

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);
}
}
}
}