Пример #1
0
    void Update()
    {
        // 发射前(淡入过程中)
        if (!this.is_launched)
        {
            float delay = 0.5f;

            // 通过修改alpha通道值淡入

            Color color = this.GetComponent <Renderer>().material.color;

            // 将[0.0f ~ delay] 范围变换为 [0.0f ~ 1.0f]
            float t = Mathf.InverseLerp(0.0f, delay, this.time);

            t = Mathf.Min(t, 1.0f);

            color.a = Mathf.Lerp(0.0f, 1.0f, t);

            this.GetComponent <Renderer>().material.color = color;

            // 经过一定时间后,发射
            if (this.time >= delay)
            {
                this.GetComponent <Rigidbody>().useGravity = true;
                this.GetComponent <Rigidbody>().velocity   = this.velocity;

                this.is_launched = true;
            }
        }

        this.time += Time.deltaTime;

        DebugPrint.print(this.GetComponent <Rigidbody>().velocity.ToString());
    }
Пример #2
0
    void Update()
    {
        // 発射される前だったら(フェードイン中だったら)…….
        if (!this.is_launched)
        {
            float delay = 0.5f;

            // アルファーでフェードインする.

            Color color = this.GetComponent <Renderer>().material.color;

            // [0.0f ~ delay] の範囲を [0.0f ~ 1.0f] に変換する
            float t = Mathf.InverseLerp(0.0f, delay, this.time);

            t = Mathf.Min(t, 1.0f);

            color.a = Mathf.Lerp(0.0f, 1.0f, t);

            this.GetComponent <Renderer>().material.color = color;

            // 一定時間が経過したら、発射.
            if (this.time >= delay)
            {
                this.GetComponent <Rigidbody>().useGravity = true;
                this.GetComponent <Rigidbody>().velocity   = this.velocity;

                this.is_launched = true;
            }
        }

        this.time += Time.deltaTime;

        DebugPrint.print(this.GetComponent <Rigidbody>().velocity.ToString());
    }
Пример #3
0
    void Update()
    {
        // 着地中だったら…….
        if (this.is_landed)
        {
            // マウスの右ボタンがクリックされたら…….
            if (Input.GetMouseButtonDown(0))
            {
                this.is_landed = false;

                // ジャンプの高さから、初速度を求める.
                float y_speed = Mathf.Sqrt(2.0f * Mathf.Abs(Physics.gravity.y) * this.JumpHeight);

                this.GetComponent <Rigidbody>().velocity = Vector3.up * y_speed;
            }
        }

        DebugPrint.print(this.is_landed.ToString());
    }
Пример #4
0
    void Update()
    {
        // 已着陆……
        if (this.is_landed)
        {
            // 点击鼠标右键……
            if (Input.GetMouseButtonDown(0))
            {
                this.is_landed = false;

                // 通过跳跃的高度,算出初始速度
                float y_speed = Mathf.Sqrt(2.0f * Mathf.Abs(Physics.gravity.y) * this.JumpHeight);

                this.GetComponent <Rigidbody>().velocity = Vector3.up * y_speed;
            }
        }

        DebugPrint.print(this.is_landed.ToString());
    }