*

Brick

  • ***
  • 25
    • View Profile
Fade in then fade out sequence
« on: June 10, 2015, 04:51:00 PM »
Hi all who read this.

I am trying to figure out how to go about setting a sequence on a text mesh.

It works if  i set one fade to the texture but will not work if i set 2 fades. this is my code:

Code: [Select]

public Transform textNumber;
bool playedOnce = false;
private Sequence s;
void Start ()
{
s = DOTween.Sequence ();
}


void Update ()
{
PlayTween ();
}

void PlayTween ()
{
if (playedOnce == false) {
if (touchCount.state == touchCount.State.START) {

print ("played the fade tween");
s.Append (textNumber.GetComponent<Renderer> ().material.DOFade (1, .5f));
s.Append (textNumber.GetComponent<Renderer> ().material.DOFade (1, 2));



playedOnce = true;
}
}
}
}

Any suggestions would be great.
Thanks

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: Fade in then fade out sequence
« Reply #1 on: June 10, 2015, 06:55:25 PM »
Hello!

You are confusing the parameters. The first DOFade parameter is the fade amount (0 to 1), while the second is the duration. In your code, you are setting the fade to 1 both times. So the material first fades from *yourMaterialAlpha* to 1, then from 1 to 1 again, so nothing seems to happen.

*

Brick

  • ***
  • 25
    • View Profile
Re: Fade in then fade out sequence
« Reply #2 on: June 10, 2015, 11:05:48 PM »
Hi Thanks for the reply.
I have been doing some testing and  first off sorry the code i pasted was after the testing so didnt make much sense. 

However, if you put a fadein and fade out it will not work.
It will only work if you have one of the fade in/out. I have set the alpha via code as it doesn't work if you set it in the inspector to get fade in. but fade out will work if set in the inspector.

Here is the code which will not work.

Code: [Select]
void Update ()
{
PlayTween ();
}

void PlayTween ()
{
if (playedOnce == false) {
if (touchCount.state == touchCount.State.START) {
// Let's move the red cube TO 0,4,0 in 2 seconds
textNumber.DOMove (new Vector3 (transform.position.x, transform.position.y, -100), 6);
print ("played the fade tween");

textNumber.GetComponent<MeshRenderer> ().material.color = new Color (1, 1, 1, 0);
s.Append (textNumber.GetComponent<Renderer> ().material.DOFade (1, 1));
s.Append (textNumber.GetComponent<Renderer> ().material.DOFade (0, 2));

playedOnce = true;


}
}
}


Simply comment out the second line and it will fade in.

I am under the impression that if you have a sequence it should fire off line by line once completed..

Any help would be greatly appreciated.. Maybe its a bug..

Thanks

*

Brick

  • ***
  • 25
    • View Profile
Re: Fade in then fade out sequence
« Reply #3 on: June 10, 2015, 11:23:28 PM »
Ok getting somewhere, To get it to work i have to set a delay the second sequence.. odd but it works now.

Let me know if there is an alternative way to do this as it still seems odd to have to add the delay.

Thanks

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: Fade in then fade out sequence
« Reply #4 on: June 11, 2015, 01:03:30 AM »
Hi,

That is weird. I tried to replicate the same Sequence you have, just to be sure I didn't mess something up in some recent update, but everything works perfectly here, without any need to add a delay between the 2 fades. Can you send me an example UnityPackage so I can check what's happening in your case?

Cheers