2017-09-28 6 views
-1

私の質問が重複しないことを願っています。 私は結束に問題があります。 私はオブジェクトの透過(フェードイン/フェードアウトループ)のクラスを作成しました。 シーンに2つのボタンを入れました。キャンバスの場所にあります。 実行後、私はキャンバスに透明オブジェクトのコマンドを書きましたが、内部のすべてのオブジェクトは透明になります(フェードインとフェードアウトループ)。 私は分かりません。 助けてください。団結の透明性3d

MyClassの

using System.Collections; 
using System.Collections.Generic; 
using UnityEngine; 
using UnityEngine.UI; 
using System.Threading; 
using System; 

public class Transparent : MonoBehaviour { 

private float duration = .7f; 
    public float waitTime; 
    IEnumerator co2; 
    // Update is called once per frame void 
    public void start_tranparecncy() 
    { 
     this.co2=this.blink(); 
     this.StartCoroutine (this.co2); 
    } 
    IEnumerator blink() { 

     //Color textureColor = this.transform.GetComponent<SpriteRenderer>().material.color; 
     Color textureColor = this.transform.GetComponent<Image>().material.color; 

     //textureColor.a = Mathf.PingPong(Time.time, duration)/duration; 
     //this.GetComponent<SpriteRenderer>().material.color = textureColor; 
     while (true) { // this could also be a condition indicating "alive or dead" 
      // we scale all axis, so they will have the same value, 
      // so we can work with a float instead of comparing vectors 
      textureColor.a=Mathf.PingPong (Time.time, duration)/duration; 
      this.transform.transform.GetComponent<Image>().material.color = textureColor; 

      // reset the timer 

      yield return new WaitForSeconds (waitTime); 



     } 
     //end of if(this.transform.childCount =0) 

    } 

    void stop_Transparency() 
    { 

     this.StopCoroutine (this.co2); 

    } 
} 

picture of my project

picture of my project

+0

可能であれば、コードを入力してください – Thalthanas

+0

それは不明です。正しい命名規則を使用してください。 _command_ではなくfunctionを意味するのでしょうか? _canvas place_とは何ですか?スクリーンスペース - オーバーレイを意味しますか?内部のものは全て透明性に向いていますか?あなたが達成しようとしているものではありませんか?ユニティの透明性? – MrDos

+0

@EmreEああ、ごめんなさい –

答えて

0

[OK]を私は、私は、それは変換ため、二重の主

this.transform.transform.GetComponent<Image>(); 

のあるあなたの問題を発見しましたあなたのキャンバス自体である親に1つ上のレベルに達します。キャンバス内のすべてがアルファ値を失います。

また、コードを少し編集しました。マテリアルカラーを使用する代わりに、イメージコンポーネントのアルファのカラー値を直接変更しました。

using System.Collections; 
using System.Collections.Generic; 
using UnityEngine; 
using UnityEngine.UI; 
using System.Threading; 
using System; 

public class Transparent : MonoBehaviour 
{ 
    private float duration = .7f; 
    public float waitTime; 
    IEnumerator co2; 

    public void start_tranparecncy() 
    { 
     this.co2 = this.blink(); 
     this.StartCoroutine(this.co2); 
    } 

    IEnumerator blink() 
    { 
     //Color textureColor = this.transform.GetComponent<SpriteRenderer>().material.color; 
     Color textureColor = this.transform.GetComponent<Image>().color; 

     //textureColor.a = Mathf.PingPong(Time.time, duration)/duration; 
     //this.GetComponent<SpriteRenderer>().material.color = textureColor; 

     while (true) 
     { // this could also be a condition indicating "alive or dead" 
      // we scale all axis, so they will have the same value, 
      // so we can work with a float instead of comparing vectors 
      textureColor.a = Mathf.PingPong(Time.time, duration)/duration; 
      this.transform.GetComponent<Image>().color = textureColor; 

      // reset the timer 

      yield return new WaitForSeconds(waitTime); 
     } 
     //end of if(this.transform.childCount =0) 

    } 

    void stop_Transparency() 
    { 
     this.StopCoroutine(this.co2); 
    } 
} 

私はキャンバス内のボタンにこのスクリプトを添付しました。また、同じボタンのOn Click()start_tranparecncy()関数を実行します。

ボタンを押すと、ボタンのアルファ値のみが変更されます。

On Click()を変更して、必要に応じて別のボタンを追加することができます。

+0

私の友人は、開始シーンでフェードイン/フェードアウトを実行する必要があります...私はstart_transparencyメソッドをスクリプトで実行します.......例えば:throw_text_p1.gameObject。 GetComponent ().start_tranparecncy();コマンド。 –

+0

ありがとうございます。私の弟 –

関連する問題