コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        if (m_sceneMain.IsGamePlay() == false)
        {
            return;
        }
        Vector3 vector = SceneMain.GetInput(m_initData.playerNo);

        rigidbody.velocity = vector * m_speed;

        // 歩行音を鳴らす
        if (rigidbody.velocity.sqrMagnitude > 0F)
        {
            walkSEObj.enabled = true;
        }
        else
        {
            walkSEObj.enabled = false;
        }

        // 移動した方向を向く
        if (rigidbody.velocity.magnitude > 0.01f)                                       //ベクトルの長さが0.01fより大きい場合にプレイヤーの向きを変える処理を入れる(0では入れないので)
        {
            detective.transform.rotation = Quaternion.LookRotation(rigidbody.velocity); //ベクトルの情報をQuaternion.LookRotationに引き渡し回転量を取得しプレイヤーを回転させる
        }
    }
コード例 #2
0
    /// <summary>
    /// 移動処理
    /// </summary>
    private void Move()
    {
        Vector3    vector    = SceneMain.GetInput(m_initData.playerNo);
        Vector3    pos       = transform.position;
        eAnimState animState = eAnimState.Stop;

        if (vector.magnitude > m_runThreshold)
        {
            animState = eAnimState.Run;
        }
        else if (vector.magnitude < 0.1f)
        {
            animState = eAnimState.Stop;
        }
        else
        {
            animState = eAnimState.Walk;
        }
        m_rigidbody.velocity = vector * m_speed;

        // 移動した方向を向く
        if (m_rigidbody.velocity.magnitude > 0.01f)                                     //ベクトルの長さが0.01fより大きい場合にプレイヤーの向きを変える処理を入れる(0では入れないので)
        {
            phantom.transform.rotation = Quaternion.LookRotation(m_rigidbody.velocity); //ベクトルの情報をQuaternion.LookRotationに引き渡し回転量を取得しプレイヤーを回転させる
        }
        // アニメーション更新
        if (m_animState != animState)
        {
            switch (animState)
            {
            case eAnimState.Stop:

                m_animator.SetTrigger("idle");
                break;

            case eAnimState.Walk:
                m_animator.SetTrigger("walk");
                break;

            case eAnimState.Run:
                m_animator.SetTrigger("run");
                // エフェクト
                if (m_runEffect == null)
                {
                    m_runEffect = Instantiate(Resources.Load("Prefabs/Effect/NoiseParticel")) as GameObject;
                    m_runEffect.transform.parent        = transform;
                    m_runEffect.transform.localPosition = Vector3.zero;
                    var particle = m_runEffect.GetComponent <ParticleSystem>();
                    var color    = particle.colorOverLifetime;
                    switch (m_phantomNo)
                    {
                    case 0:
                        color.color = Color.red;
                        break;

                    case 1:
                        color.color = Color.blue;
                        break;

                    case 2:
                        color.color = Color.green;
                        break;
                    }
                }
                break;
            }
            m_animState = animState;
        }

        // 透過処理
        {
            Color color;
            // 騒音状態更新
            if (m_animState == eAnimState.Run)
            {
                m_appearTime = AppearTime;
            }
            if (m_appearTime > 0.0f)                                        // 騒音状態
            {
                m_appearTime -= Time.deltaTime;
                if (m_appearTime <= 0.0f)
                {
                    if (m_runEffect != null)
                    {
                        GameObject.Destroy(m_runEffect);
                        m_runEffect = null;
                    }
                }
                m_renderer.material = m_normalMat;
                color   = m_renderer.material.color;
                color.a = 1.0f;
                m_renderer.material.color = color;
                m_textMeshObj.SetActive(true);
            }
            else if (vector.magnitude < m_visibleThreshold)                 // 完全透過状態
            {
                m_renderer.material = m_fadeMat;
                color   = m_renderer.material.color;
                color.a = 0.0f;
                m_renderer.material.color = color;
                m_textMeshObj.SetActive(false);
            }
            else                                                            // 歩き
            {
                m_renderer.material = m_fadeMat;
                color   = m_renderer.material.color;
                color.a = Mathf.Lerp(0.0f, 1.0f, (vector.magnitude - m_visibleThreshold) / (m_runThreshold - m_visibleThreshold));
                m_renderer.material.color = color;
                m_textMeshObj.SetActive(false);
            }
        }
    }