Search Unity

how do you insert an animation into a color list

Discussion in 'Scripting' started by michellynitecki, Jun 17, 2019.

  1. michellynitecki

    michellynitecki

    Joined:
    Apr 26, 2019
    Posts:
    43
    would you have any tips? I did it differently and nothing.because even I tried to animate the color list
    Code (CSharp):
    1.     public List<Color> _color = new List<Color>();
    2.     public Animation Anim;
    3.  
    4.     void Start() {
    5.         Color color = _color[4][5][6][7];
    6.         Anim[4][5][6][7].GetComponent<Animation>().Play();
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    I think you might be looking for a Unity Gradient?

    https://docs.unity3d.com/ScriptReference/Gradient.html

    With that you can select where in the gradient you get the color from.

    If you are using a list of colors above, you can either select the one you want from the List and use it, or else lerp between the two you are between gradually, if it's not discrete steps.

    The syntax you have above will not work: you can dereference one thing at a time. If you want to iterate all the colors, use something like a for loop to do what you want to each of them.
     
  3. michellynitecki

    michellynitecki

    Joined:
    Apr 26, 2019
    Posts:
    43
    I took a look at the gradient, but I did not understand anything, in relation to animation
    my script alone already works. with loop etc, but without animation, now when i insert animation this is what is difficult for me
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    If you're just looking to animate a color property, can you just make an animation and start it playing?

    If you're looking to control color through code, that's easy to do but first you have to define what you want to do:

    -> Cycle instantly through each the colors? Then just set them one at a time with an interval between them, either with update tracking time yourself, or using a Coroutine and yielding for the time interval.

    -> Lerp them smoothly from one color to another? Use Color.Lerp and steadily move it through the ranges you want, or use Gradient and do it all at once in one linear line.

    Something else entirely?