コード例 #1
0
    protected void createDebris()
    {
        int num = Random.Range(50, 100);

        for (int i = 0; i < num; ++i)
        {
            float      distance    = 0;
            GameObject pref        = null;
            float      rare_random = Random.Range(0, 100);
            if (rare_random < 5)
            {
                distance = Random.Range(150.0f, 500.0f);
                pref     = m_titaniumDebrisPrefab;
            }
            else if (rare_random < 15)
            {
                distance = Random.Range(100.0f, 400.0f);
                pref     = m_goldDebrisPrefab;
            }
            else if (rare_random < 45)
            {
                distance = Random.Range(100.0f, 200.0f);
                pref     = m_copperDebrisPrefab;
            }
            else
            {
                distance = Random.Range(20.0f, 200.0f);
                pref     = m_ironDebrisPrefab;
            }

            float   theta           = Random.Range(-15.0f, 15.0f) + (Random.Range(0, 100) < 50 ? 0 : 180.0f);
            Vector3 pos             = new Vector3(Mathf.Cos(theta / 180.0f * Mathf.PI), Mathf.Sin(theta / 180.0f * Mathf.PI), 0) * distance;
            Vector3 euler           = new Vector3(Random.Range(0, 30), Random.Range(0, 30), 0);
            Vector3 velocity        = new Vector3(Random.Range(-0.5f, 0.5f), Random.Range(-0.5f, 0.5f), 0);
            Vector3 scale           = new Vector3(Random.Range(0.5f, 1.0f), Random.Range(0.5f, 2f), Random.Range(0.5f, 1.0f));
            Vector3 angularVelocity = new Vector3(0, Random.Range(0, 2), 0);

            Quaternion rot = Quaternion.Euler(euler);
            GameObject obj = Instantiate(pref, pos, rot, transform.parent);
            obj.transform.localScale = scale;
            DebrisMain debris = obj.GetComponent <DebrisMain>();
            debris.m_anglarVelocity = angularVelocity;
            debris.m_velocity       = velocity;
        }
    }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        if (Globals.GetInstance().m_bPauseGame)
        {
            return;
        }

        float v = 1.0f - Mathf.Clamp01((transform.position.y + 50.0f) / 100.0f);

        m_hightSlider.value = v;
        m_playTimer        += Time.deltaTime;

        float air = 0.1f;
        float f   = 1.0f;

        Vector3 d_force = Vector3.zero;
        Vector3 r_force = Vector3.zero;

        Vector3 forward = m_player.transform.rotation * Vector3.forward;
        Vector3 right   = m_player.transform.rotation * Vector3.right;
        Vector3 up      = m_player.transform.rotation * Vector3.up;

        Vector3   g_pos     = transform.position;
        Vector3   f_at      = m_player.transform.position - forward * 0.5f;
        Rigidbody rigidbody = GetComponent <Rigidbody>();

        if (rigidbody == null)
        {
            attachRigidbody();
            return;
        }

        if (m_air == 0)
        {
            //GameOver
            m_gameoverTimer += Time.deltaTime;
            if (m_gameoverTimer > 1.0f)
            {
                Globals.GetInstance().m_cost           = (100 - m_air) * 10.0f + m_playTimer;
                Globals.GetInstance().m_bStartGameOver = true;
            }
            return;
        }

        if (Input.GetMouseButton(0))
        {
            d_force += forward * f * 2;
            //rigidbody.AddForceAtPosition(forward * f, f_at);
            air += 2.0f;
            m_ptclBack.gameObject.SetActive(true);
            if (!m_ptclBack.isPlaying)
            {
                m_ptclBack.Play();
            }
        }
        if (Input.GetMouseButton(1))
        {
            d_force -= forward * f;
            //rigidbody.AddForceAtPosition(-forward * f, f_at);
            air += 1.0f;
            m_ptclFront.gameObject.SetActive(true);
            if (!m_ptclFront.isPlaying)
            {
                m_ptclFront.Play();
            }
        }
        if (Input.GetKey(KeyCode.W))
        {
            d_force -= up * f;
            //rigidbody.AddForceAtPosition(-up * f, f_at);
            air += 1.0f;
            m_ptclTop.gameObject.SetActive(true);
            if (!m_ptclTop.isPlaying)
            {
                m_ptclTop.Play();
            }
        }
        if (Input.GetKey(KeyCode.S))
        {
            d_force += up * f;
            //rigidbody.AddForceAtPosition(up * f, f_at);
            air += 1.0f;
            m_ptclBottom.gameObject.SetActive(true);
            if (!m_ptclBottom.isPlaying)
            {
                m_ptclBottom.Play();
            }
        }
        if (Input.GetKey(KeyCode.A))
        //if (Input.GetKey(KeyCode.Q))
        {
            d_force -= right * f;
            //rigidbody.AddForceAtPosition(-right * f, f_at);
            air += 1.0f;
            m_ptclRight.gameObject.SetActive(true);
            if (!m_ptclRight.isPlaying)
            {
                m_ptclRight.Play();
            }
        }
        if (Input.GetKey(KeyCode.D))
        //if (Input.GetKey(KeyCode.E))
        {
            d_force += right * f;
            //rigidbody.AddForceAtPosition(right * f, f_at);
            air += 1.0f;
            m_ptclLeft.gameObject.SetActive(true);
            if (!m_ptclLeft.isPlaying)
            {
                m_ptclLeft.Play();
            }
        }
        rigidbody.AddForceAtPosition(d_force, f_at);

        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (m_grabedObject)
            {
                StartCoroutine(ungrabDebris());
            }
        }

        Vector3 angularVelocity = rigidbody.angularVelocity;

        angularVelocity.x = angularVelocity.z = 0;

        Vector3 velocity = rigidbody.velocity;

        velocity.z = 0;

        if (!m_isFlying)
        {
            air              = -1.0f; //増やす
            m_airSupply      = Time.deltaTime * 0.4f;
            velocity        *= (1.0f - Time.deltaTime);
            angularVelocity *= (1.0f - Time.deltaTime);

            //if (velocity.magnitude < minVelocity)
            //{
            //    velocity = Vector3.zero;
            //}
            //if (angularVelocity.magnitude < minAngularVelocity)
            //{
            //    angularVelocity = Vector3.zero;
            //}
            if ((angularVelocity.magnitude < minAngularVelocity) && (velocity.magnitude < minVelocity))
            {
                if (m_grabedObject)
                {
                    DebrisMain debris                    = m_grabedObject.GetComponent <DebrisMain>();
                    Globals.GetInstance().m_mass         = debris.GetMass();
                    Globals.GetInstance().m_difficulty   = debris.GetDistance();
                    Globals.GetInstance().m_rare         = debris.GetRare();
                    Globals.GetInstance().m_cost         = (100 - m_air + m_airSupply) * 10.0f + m_playTimer;
                    Globals.GetInstance().m_bStartResult = true;

                    Destroy(gameObject.GetComponent <Rigidbody>());
                    m_grabedObject.transform.SetParent(m_sceneRoot);
                    m_grabedObject = null;
                }
                m_isGrabing = false;
            }
        }

        m_air -= (air * Time.deltaTime * 0.4f);
        m_air  = Mathf.Clamp(m_air, 0.0f, 100);

        m_airSlider.value = m_air / 100.0f;
        m_airText.text    = string.Format("{0:0.00} %", m_air);

        if (m_air < 20)
        {
            m_airSliderFill.color = new Color(192.0f / 255.0f, 0, 0);
        }

        if (m_air == 0)
        {
            if (m_grabedObject)
            {
                //StartCoroutine(ungrabDebris());
            }
            m_playerAnimator.SetBool("isFail", true);
        }

        rigidbody.velocity        = velocity;
        rigidbody.angularVelocity = angularVelocity;

        //Vector3 angles = transform.eulerAngles;
        //angles.x = angles.z = 0;
        //transform.eulerAngles = angles;

        //Vector3 position = transform.position;
        //position.z = 0;
        //transform.position = position;

        m_playerAnimator.SetBool("isFlying", m_isFlying);
        m_playerAnimator.SetBool("isGrabing", m_isGrabing);
    }