/***
- 太阳系
- 太阳系八大行星运行脚本
- 本脚本挂载在空对象ScriptsManagers上
- 行星公转同时自转
- 鼠标点击跳转场景,新场景中可以旋转缩放行星
- 非子萧
- 201606
*/
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using UnityEngine.SceneManagement;
public class Solar : MonoBehaviour
{
public Camera _camPlayer;//行星的摄像机
//public Camera _MainCamera;
//public Camera _EarthCamera;
//public GameObject _panel;
// public Transform Player;
public Transform TrSun; //定义太阳
public Transform TrMercury; //定义水星Mercury
public Transform TrVenus; //定义金星Venus
public Transform TrEarth;// 定义地球
public Transform TrMoon;// 定义月球
public Transform TrMars; //定义火星Mars
public Transform TrJupiter; //定义木星Jupiter
public Transform TrSaturn; //定义土星Saturn
public Transform TrUranus; //定义天王星Uranus
public Transform TrNeptune; //定义海王星Neptune
public float FlRotaSpeedSelf = 10; // 自转速度
public float FlRotaSpeedCommMercury = 1; // 水星公转速度
public float FlRotaSpeedCommVenus = 1; // 金星Venus公转速度
public float FlRotaSpeedCommEarth = 1; // 地球公转速度
public float FlRotaSpeedCommMoon = 1; //月球公转速度
public float FlRotaSpeedCommMars = 1; // 火星Mars公转速度
public float FlRotaSpeedCommJupiter = 1; // 木星Jupiter公转速度
public float FlRotaSpeedCommSaturn = 1; // 土星Jupiter公转速度
public float FlRotaSpeedCommUranus = 1; //天王星Uranus公转速度
public float FlRotaSpeedCommNeptune = 1; // 海王星Neptune公转速度
private void Awake()
{
//DontDestroyOnLoad(this);
}
void Update()
{
//太阳系由近到远各行星,水星Mercury、金星Venus、地球Earth、火星Mars、木星Jupiter、土星Saturn、天王星Uranus、海王星Neptune
//太阳自转
TrSun.Rotate(Vector3.up * FlRotaSpeedSelf * Time.deltaTime);
//水星Mercury
TrMercury.Rotate(Vector3.up * FlRotaSpeedSelf * Time.deltaTime);
TrMercury.RotateAround(TrSun.position, Vector3.up, FlRotaSpeedCommMercury * Time.deltaTime);
//金星
TrVenus.Rotate(Vector3.up * FlRotaSpeedSelf * Time.deltaTime);
TrVenus.RotateAround(TrSun.position, Vector3.up, FlRotaSpeedCommVenus * Time.deltaTime);
// 地球自转+公转
TrEarth.Rotate(Vector3.up * FlRotaSpeedSelf * Time.deltaTime);
TrEarth.RotateAround(TrSun.position, Vector3.up, FlRotaSpeedCommEarth * Time.deltaTime);
// 月球为地球卫星;自转+绕地球公转
TrMoon.Rotate(Vector3.up * FlRotaSpeedSelf * Time.deltaTime);
TrMoon.RotateAround(TrEarth.position, Vector3.up, FlRotaSpeedCommMoon * Time.deltaTime);
//火星
TrMars.Rotate(Vector3.up * FlRotaSpeedSelf * Time.deltaTime);
TrMars.RotateAround(TrSun.position, Vector3.up, FlRotaSpeedCommMars * Time.deltaTime);
//木星
TrJupiter.Rotate(Vector3.up * FlRotaSpeedSelf * Time.deltaTime);
TrJupiter.RotateAround(TrSun.position, Vector3.up, FlRotaSpeedCommJupiter * Time.deltaTime);
//土星
TrSaturn.Rotate(Vector3.up * FlRotaSpeedSelf * Time.deltaTime);
TrSaturn.RotateAround(TrSun.position, Vector3.up, FlRotaSpeedCommSaturn * Time.deltaTime);
//天王星
TrUranus.Rotate(Vector3.up * FlRotaSpeedSelf * Time.deltaTime);
TrUranus.RotateAround(TrSun.position, Vector3.up, FlRotaSpeedCommUranus * Time.deltaTime);
//海王星
TrNeptune.Rotate(Vector3.up * FlRotaSpeedSelf * Time.deltaTime);
TrNeptune.RotateAround(TrSun.position, Vector3.up, FlRotaSpeedCommNeptune * Time.deltaTime);
#region 双击
int touchNum = Input.touchCount;
if (touchNum > 0)
{
Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Began)
{
RaycastHit hitinfo;
Ray ray = Camera.main.ScreenPointToRay(touch.position);
bool isHit = Physics.Raycast(ray, out hitinfo);
if (touch.tapCount == 1)
{
//if (isHit)
//{
// if (hit.collider.tag == "Terrain")
// {
// transform.position = new Vector3(hit.point.x, hit.point.y + 0.5f, hit.point.z);
// }
//}
}
else
{
if (touch.tapCount == 2)
{
if (isHit)
{
//if (hitinfo.collider.tag == "Player")
//{
// m_rigidbody.AddForce(Vector3.up * 300f);
// tip.text = touch.tapCount.ToString();
//}
//如果鼠标点击的是那个行星,就跳转到那个行星的小场景
if (hitinfo.collider.tag == "Mercury")
{
SceneManager.LoadScene(1);
}
if (hitinfo.collider.tag == "Venus")
{
SceneManager.LoadScene(2);
}
if (hitinfo.collider.tag == "Earth")
{
SceneManager.LoadSceneAsync(3);
}
if (hitinfo.collider.tag == "Mars")
{
SceneManager.LoadScene(4);
}
if (hitinfo.collider.tag == "Jupiter")
{
SceneManager.LoadScene(5);
}
if (hitinfo.collider.tag == "Saturn")
{
SceneManager.LoadScene(6);
}
if (hitinfo.collider.tag == "Uranus")
{
SceneManager.LoadScene(7);
}
if (hitinfo.collider.tag == "Neptune")
{
SceneManager.LoadScene(8);
}
if (hitinfo.collider.tag == "Moon")
{
SceneManager.LoadScene(9);
}
if (hitinfo.collider.tag == "Sun")
{
SceneManager.LoadScene(10);
}
}
}
}
}
}
#endregion
//射线检查
//检测鼠标左键的
//if (Input.GetMouseButtonDown(0))
//{
// //鼠标的屏幕坐标空间位置转射线
// Ray _ray = _camPlayer.ScreenPointToRay(Input.mousePosition);
// //射线碰触点信息
// RaycastHit hitinfo;
// //射线检测,相关检测信息保存到RaycastHit 结构中
// if (Physics.Raycast(_ray, out hitinfo))
// {
// //如果鼠标点击的是那个行星,就跳转到那个行星的小场景
// if (hitinfo.collider.tag=="Mercury")
// {
// SceneManager.LoadScene(1);
// }
// if (hitinfo.collider.tag == "Venus")
// {
// SceneManager.LoadScene(2);
// }
// if (hitinfo.collider.tag == "Earth")
// {
// SceneManager.LoadSceneAsync(3);
// }
// if (hitinfo.collider.tag == "Mars")
// {
// SceneManager.LoadScene(4);
// }
// if (hitinfo.collider.tag == "Jupiter")
// {
// SceneManager.LoadScene(5);
// }
// if (hitinfo.collider.tag == "Saturn")
// {
// SceneManager.LoadScene(6);
// }
// if (hitinfo.collider.tag == "Uranus")
// {
// SceneManager.LoadScene(7);
// }
// if (hitinfo.collider.tag == "Neptune")
// {
// SceneManager.LoadScene(8);
// }
// if (hitinfo.collider.tag == "Moon")
// {
// SceneManager.LoadScene(9);
// }
// if (hitinfo.collider.tag == "Sun")
// {
// SceneManager.LoadScene(10);
// }
// }
// }
}
}
网友评论