双击

作者: 萧非子 | 来源:发表于2017-12-22 19:30 被阅读9次

/***

  • 太阳系
  • 太阳系八大行星运行脚本
  • 本脚本挂载在空对象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);
    //        }
    //    }
   // }
}

}

相关文章

  • 双击

    /*** 太阳系 太阳系八大行星运行脚本 本脚本挂载在空对象ScriptsManagers上 行星公转同时自转 鼠...

  • android双击退出,用户明确双击退出时,不显示提示

    // 特性:用户明确双击退出时,不显示提示,意外单击时,提示双击可退出应用 // 自我测试,明确双击退出时,双击时...

  • ps中怎么修改图层的颜色

    2、双击图层解锁3、双击图层,弹出图层样式

  • 二、AE+C#之地图图层基本操作

    双击‘通过AddLayerFromFile加载’,增加代码: 双击‘通过AddShapeFile加载’,增加代码:...

  • 阻止 iOS 双击页面上/下滑动

    参考文章:禁止IOS双击上滑当在UIWebView上双击时防止网页滚动 背景 在 iOS 系统下,双击网页会触发整...

  • Android双击事件实现

    双击退出应用 双击响应事件 利用Handler控制点击事件

  • 不能双击

    所有的双击确认都不可以,手指不能连续击打两下,眼睛不能眨两下,跟电脑或手机说出确认两个字。所有的,只有是让电脑能行...

  • 双击666

    我20你的小呀小苹果

  • 双击棍

  • 双击事件

    有些时候我们会遇到双击事件,如何设置双击事件。 在你的点击事件里写下一下判断 System.arraycopy(d...

网友评论

      本文标题:双击

      本文链接:https://www.haomeiwen.com/subject/hsmxgxtx.html