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

Animation vs script

Discussion in 'Scripting' started by VSMGames, Feb 16, 2020.

  1. VSMGames

    VSMGames

    Joined:
    Jan 12, 2020
    Posts:
    47
    I have a question, which one is considered a better approach for performance etc reasons. I have a 2D gameobject and I'm planning on changing its color gradually during a game over sequence. Is it preferred to use animation for this or code changing the sprite renderer color values? Or is it just a case choosing what ever approach suits you better?
     
  2. diXime

    diXime

    Joined:
    Oct 2, 2018
    Posts:
    162
    Hello,
    Color changing isn't very demanding, and it depends if you're aiming a specific time rate or something based on events. I would try to chrono test to see which is fastest, but honestly my approach would be not to add an entire component just to change the color, but if you already have an animation component it should be fine to use it, just to group up your work and not having different scripts doing different things, for the sake of clarity.
     
  3. VSMGames

    VSMGames

    Joined:
    Jan 12, 2020
    Posts:
    47
    Thanks for the replay. I went with code this time because I'm planning to create multiple characters and all of them have many different game over sequence animations so creating one extra for all of them with only color change added seemed to be more time consuming than to write a code which fits for all.