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

Trying to get my character darker once passing through a shadow

Discussion in '2D' started by Markeus1989, Mar 23, 2016.

  1. Markeus1989

    Markeus1989

    Joined:
    Jul 26, 2014
    Posts:
    81
    Screenshot 2016-03-22 18.19.42.png

    What's the easiest way to accomplish this?
     
  2. jc-drile77

    jc-drile77

    Joined:
    Jul 1, 2014
    Posts:
    229
    The easiest? Just change it´s color:
    Code (CSharp):
    1.  SpriteRenderer renderer = GetComponent<SpriteRenderer>();
    2.   renderer.color = new Color(r, g, b, alpha);
    3. //or renderer.color  =  black; //Too dark?
    Edit:
    Oh and even better and easier, take the tree sprite and slice it into 2 different spritres (shadow and tree), set the shadow sorting layer over player´s sorting layer and enemies, you will get better results.
    The shadow has to have some alpha transparency (just in case)
     
    Last edited: Mar 23, 2016
  3. Markeus1989

    Markeus1989

    Joined:
    Jul 26, 2014
    Posts:
    81
    @jc-drile77 Pure Genius! That was so simple haha. Thanks a bunch!
     
  4. jc-drile77

    jc-drile77

    Joined:
    Jul 1, 2014
    Posts:
    229
    No problem ! :)
    The game is looking great;)
     
    Markeus1989 likes this.
  5. Markeus1989

    Markeus1989

    Joined:
    Jul 26, 2014
    Posts:
    81