add ckg
plantilla base para movimiento básico
This commit is contained in:
40
Assets/Game Kit Controller/Scripts/Demo/solarSystem.cs
Normal file
40
Assets/Game Kit Controller/Scripts/Demo/solarSystem.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user