Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by gccps3c3c3c · Jan 02, 2017 at 04:27 PM · 2dlighting2d-platformerlighteffect

Terraria lighting

sorry for my bad english . i saw a lot of posts and i can't solve this problem . i making a 2D sandbox game like Terraria and Starbound . this is my game : alt text

i can make a basic lighting but the lighting if filling the whole terrain . i want this :

alt text

someone can help me please ?

ice-screenshot-20170102-234647.png (25.9 kB)
ice-screenshot-20170102-234236.png (30.7 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by AnotherValidUsername · Jan 19, 2017 at 09:08 PM

Every Tile needs to have access to any of the surroundet tiles. They should have the same Script. My Full Script for this is not ready, but here are some Pieces:

 public GameObject LeftBlock;
 public GameObject RightBlock;
 public GameObject UpBlock;
 public GameObject DownBlock;
 public string Improve;
 public int Blockvalue;     //Just the identification Number, Blockvalue 0 = air
 public int Lightlevel = 5; //The Lightlevel of this Block, 15 = max.
 public bool Lighted = false; //Whether a Lightsource is near the Block
 private Color LightTone;
 private bool Surroundet = false; //Whether the Block is totally surroundet by other Tiles
 public bool free = false;
 public bool Walled = false;  //Whether the Block touches a background wall
 public bool Surroundable = true;
 private float FreeFloat;
 public bool CHANGE = false;int LightLevelSeek(int Minusint)
 {
     int ReturnLevel = 0;
     int Right = 0;
     int Left = 0;
     int Up = 0;
     int Down = 0;
     if (RightBlock != null) { Right = RightBlock.GetComponent<Block>().Lightlevel; }
     if (LeftBlock != null) { Left = LeftBlock.GetComponent<Block>().Lightlevel; }
     if (UpBlock != null) { Up = UpBlock.GetComponent<Block>().Lightlevel; }
     if (DownBlock != null) { Down = DownBlock.GetComponent<Block>().Lightlevel; }
     ReturnLevel = System.Math.Max(System.Math.Max(System.Math.Max(Left, Right), Up), Down);
     return ReturnLevel - Minusint;
 }
 void Rendering()
 {
     if (CHANGE)
     {
         if (RightBlock != null && LeftBlock != null && UpBlock != null && DownBlock != null && Surroundable)
         { Surroundet = true; free = false; }
         if (RightBlock == null || LeftBlock == null || UpBlock == null || DownBlock == null)
         { Surroundet = false; free = false; }
         if (RightBlock == null && LeftBlock == null && UpBlock == null && DownBlock == null)
         { Surroundet = false; free = true; }
         CHANGE = false;
     }
     if (Lighted && Blockvalue != 0)
     { Lightlevel = 15; }
     else if (!Lighted)
     {
         if (Walled || Surroundet)
         {
             if (LightLevelSeek(3) > 0)
             { Lightlevel = LightLevelSeek(3); }
             else
             { Lightlevel = 1; }
         }
         if (!Walled && !Surroundet)
         {
             Lightlevel = 15;
         }
     }
     if (Blockvalue == 0 && Walled)
     {
         FreeFloat = (float)Lightlevel / 15;
         LightTone.a = 1F - FreeFloat;
         GetComponent<SpriteRenderer>().color = LightTone;
     }
     else if (Blockvalue == 0 && !Walled)
     {
         GetComponent<SpriteRenderer>().color = Color.clear;
     }
     else
     {
         LightTone.r = (float)Lightlevel / 15;
         LightTone.g = (float)Lightlevel / 15;
         LightTone.b = (float)Lightlevel / 15;
         GetComponent<SpriteRenderer>().color = LightTone;
     }
 }

Hope, that will work, just Update Rendering when The Tile is On the Screen, else it would take too much performance down...

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image meebou · Apr 02, 2020 at 05:37 PM 0
Share

Okay, your post is almost three years old... I have a question. You say, add a script to every tile? Serious? First. You cannot add a script to a tile in unitys tilemap system.

So then you mean, write your own tilemap system and every tile is actually a gameobject?? So we talking about terraria where the smallest world has 4 million tiles. You want create 4 million gameobjects? $$anonymous$$aybe i am wrong but i don't think this could work somehow...

Is there any solution how to make that terraria lightning for tilemaps? :-)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Modify 2D Point Light Distance in runtime? 1 Answer

How to optimize the lighting in Android for best performance? 1 Answer

Trying to create 2D pixel art lighting 1 Answer

2D Lighting Effects in Unity? 0 Answers

Flickering circle of light around character 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges