Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Ping Pong Wait Between

Discussion in 'Scripting' started by sherlockturtle, Oct 14, 2014.

  1. sherlockturtle

    sherlockturtle

    Joined:
    Jan 23, 2012
    Posts:
    592
    I am trying to ping pong between two colors, and once it gets to one end to wait a few seconds, but I am unable to figure it out. So, once it gets to either black or white to wait a few seconds then keep going. Any thoughts?


    Code (csharp):
    1.  
    2.   float t = Mathf.PingPong(Time.time, Duration) / Duration;
    3.   renderer.material.color = Color.Lerp(Color.white, Color.black, t);
    4.  
     
  2. Hippiecode

    Hippiecode

    Joined:
    Feb 13, 2012
    Posts:
    110
    try it once
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class test : MonoBehaviour {
    5.  
    6.     public float duration,durationdivision;
    7.     void Start () {
    8.  
    9.         duration = 1f;
    10.         durationdivision = 0.5f;
    11.     }
    12.  
    13.     void Update () {
    14.  
    15.         float t = Mathf.PingPong(Time.time, duration) / durationdivision;
    16.         renderer.material.color = Color.Lerp(Color.white, Color.black, t);
    17.     }
    18. }
    19.  
     
  3. sherlockturtle

    sherlockturtle

    Joined:
    Jan 23, 2012
    Posts:
    592
    That kind of works, but I need it to go fully black,wait x seconds, then transition in y seconds then wait as fully white for x seconds. IF you do what you said it only stops at one end, can I make it stop at both?


    Thank you!