2016-06-21 8 views
-1

thisビデオをご覧ください。Unity3D:コレクティブアイコンとテキストを画面上にフラッシュする方法

45秒でCODゴーストアイコンが点滅し、その下にテキストが表示されます。 私は自分のゲームで同じことを達成したいと思います。 私は初心者ですが、ビデオをスローダウンするとスケーリングが増えていることがわかります。そのため、変形やパーティクルシステムがスプラッシュ効果に適用されている可能性があります。

+0

あなたも何かをしようとしましたか?動作していないコードがありますか? – Programmer

+0

@Programmer私は初心者ですが、これを達成する方法はありません。私はParticleシステムを使用してテキストの後ろにスプラッシュを施しましたが、それは私が望むものから1つだけです。 –

+0

大きな理由はありません。少なくとも、あなたはどこに問題があるのか​​言及する必要があります。初心者の方はhttp://unity3d.com/learn/tutorials/topics/scripting – Programmer

答えて

1

これらはすべてスクリプトから行うことができます。そのビデオを見てから、これらは、その旨を複製するために従うべき手順は次のとおりです。

.Imageは

(画像を有効にします)をゆっくりとそれを縮小した画像は非常に大きな作りに表示されます。

.WAIT 0.3

ための.textに表示されます(テキストを有効にします)

は、テキストが非常に大きな作りゆっくりとそれをスケールダウン。これを行うには、フォントを大きい数字から小さな数字に変更します。 1

.Blinkテキスト01にテキスト(Color.a)のアルファ値を切り替えることにより4

.WAIT。アルファ0は表示されず、1が表示されます。各トグル後に0.1秒待ってください。 forループでこれを行うことができます。

の.text消える(無効テキスト)0.3

.Imageため

.WAITは、その後縮小 は、画像のサイズを取得するに分割消滅します2. 時間の経過とともにその値にスケールします。

画像を拡大縮小している間に、画像のアルファ値を1から0に変更します。これは徐々に表示されなくなります。

今すぐ画像を無効にしてください。それでおしまい。

私はこのコードを作成し、ステップ#3の後にパーティクルを追加するように修正することができます。以下は、それが次のようになります。

enter image description here

コードを使用するには:

ゲームオブジェクトに行くことによってUIテキストを作成する - >UI - >テキストを。 >UI - - >画像

ゲームオブジェクトに行くことによって画面に表示されます UIイメージを作成します。

テキストを画像の下に置きます。

テキストの設定を、下の画像の丸で囲んだテキストのプロパティと赤の文字に合わせて変更します。 TextImageの両方のコンポーネントの変更が完了したら、コードを実行する前に表示されないように無効にします。

スクリプトをCanvasに添付し、スクリプト内のtextToAnimateスロットにドラッグします。スクリプト内のimageToAnimateスロットに画像をドラッグします。以下は

enter image description here

これを行うための完全なコードです:

using UnityEngine; 
using System.Collections; 
using UnityEngine.UI; 

public class Test : MonoBehaviour 
{ 
    public Text textToAnimate; 
    public Image imageToAnimate; 

    // Use this for initialization 
    void Start() 
    { 
     StartCoroutine(CODGhostEffect(textToAnimate, imageToAnimate)); 
    } 

    private IEnumerator CODGhostEffect(Text text, Image image) 
    { 
     //Step 1 Enable Image 
     image.gameObject.SetActive(true); 

     Color defaultTextColor = text.color; 

     Color invisibleTextColor = text.color; 
     invisibleTextColor.a = 0; //Set Alpha to 0 

     //Image RectTransform 
     RectTransform imageRect = image.GetComponent<RectTransform>(); 
     Vector2 defaultImageSize = Vector2.zero; 
     defaultImageSize = imageRect.sizeDelta; 

     //Make the size of the Image to be 5x bigger then scale it back to be original size over time 
     Vector2 scaledImageSize = defaultImageSize * 5; 
     imageRect.sizeDelta = scaledImageSize; //Set the image size to be 5x 
     float imageAppearTime = 0.3f; 
     float counter = 0; 
     while (counter < imageAppearTime) 
     { 
      counter += Time.deltaTime; 
      float time = counter/imageAppearTime; 

      //Scale the image back to the original Size size OverTime 
      imageRect.sizeDelta = Vector2.Lerp(scaledImageSize, defaultImageSize, time); 
      yield return null; 
     } 

     //Step 2 Wait for 0.3 Seconds 
     yield return new WaitForSeconds(0.3f); 


     //Step 3 Enable Text 
     text.gameObject.SetActive(true); 

     //Make the font size of the Text to be 4x bigger then scale it back to be original size over time 
     int defaultTextSize = text.fontSize; 
     int scaledTextSize = defaultTextSize * 4; 
     text.fontSize = scaledTextSize; //Set the text font size to be 4x 

     float textAppearTime = 0.2f; 
     counter = 0; 
     while (counter < imageAppearTime) 
     { 
      counter += Time.deltaTime; 
      float time = counter/textAppearTime; 

      //Scale the text font size back to the original Size OverTime 
      text.fontSize = (int)Mathf.Lerp(scaledTextSize, defaultTextSize, time); 
      yield return null; 
     } 

     //Step 4 Wait for 1 Seconds 
     yield return new WaitForSeconds(1.0f); 

     float textBlinkTime = 0.1f; //Time between blinking Text 
     WaitForSeconds waitTime = new WaitForSeconds(textBlinkTime); 

     //Step 5 Blink Text 
     /////////////////////////Flash Text///////////////////////// 
     for (int i = 0; i < 4; i++) 
     { 
      //Hide Text by setting alpha to 0 
      text.color = invisibleTextColor; 

      yield return waitTime; //Wait 

      //Show Text by setting alpha to defaultvalue 
      text.color = defaultTextColor; 

      yield return waitTime; //again 
     } 

     //Step 6 Disable Text 
     text.gameObject.SetActive(false); 

     //Reset text color to default color 
     text.color = defaultTextColor; 

     /////////////////////////SLOWLY MAKE Image DISAPPEAR///////////////////////// 
     Color defaultImageColor = image.color; 
     Color invisibleImageColor = image.color; 
     invisibleImageColor.a = 0; //Set Alpha to 0 


     Vector2 halfImageSize = Vector2.zero; 
     halfImageSize = defaultImageSize/2; 

     //Step 7 Wait for 3 Seconds 
     yield return new WaitForSeconds(0.3f); 

     //Step 8 Animate Image disappearance 
     float imageDisappearTime = 0.2f; //How long to hide the UI Image (0.2 seconds) 
     counter = 0; 
     while (counter < imageDisappearTime) 
     { 
      counter += Time.deltaTime; 
      float time = counter/imageDisappearTime; 

      //Scale to half size OverTime 
      imageRect.sizeDelta = Vector2.Lerp(defaultImageSize, halfImageSize, time); 

      //Fade OverTime 
      image.color = Color.Lerp(defaultImageColor, invisibleImageColor, time); 
      yield return null; 
     } 

     //Disable Image 
     image.gameObject.SetActive(false); 

     //Reset image size to default size 
     imageRect.sizeDelta = defaultImageSize; 

     //Reset image color to default color 
     image.color = defaultImageColor; 
    } 
} 
+0

okeh、私はそれを試す前に少し時間をください。 –

+1

@Softxide覚えておいてください。うまくいかない場合、私はそのイメージを働かせて間違ったことをしました。私は私の側で完璧にうまく動作します。ここにUIチュートリアルがあります。http://unity3d.com/learn/tutorials/topics/user-interface-ui – Programmer

+0

チャームのような働きをしてくれてありがとう、私は実験を続ける予定で、今後も連絡があります –

関連する問題