- Home /
Problem tekrarlanabilir veya güncel değil
Object sprite changes
Hello guys I am working on a project but I have a little problem (I'm newbie).I want it to check whether there is soil on the lawn, if there is any, I want the soil to turn into grass, and in its grass to soil.Can someone help how to do it? (My English is not good sorry)
Answer by Quickz · Apr 15, 2020 at 03:26 PM
You can try using Physics.OverlapBox/Physics2D.OverlapBox method to get all colliders in a certain region, let's say the lawn. Then you can iterate through those colliders and check which ones have a soil component.
Here are a few references you might find useful: https://docs.unity3d.com/ScriptReference/Physics.BoxCast.html https://docs.unity3d.com/ScriptReference/Physics2D.OverlapBox.html https://docs.unity3d.com/ScriptReference/GameObject.GetComponent.html https://docs.unity3d.com/ScriptReference/Object.Instantiate.html https://docs.unity3d.com/ScriptReference/Object.Destroy.html
is there any tutorial videos of that because I need to see an example and thanks for the help.
Regarding tutorials, I don't have a specific one in $$anonymous$$d to give you. You can try checking out these two channels if you want to. They might have some learning material:
https://www.youtube.com/user/Brackeys
https://www.youtube.com/user/Unity3D/
About examples, I cooked one up. You can try playing around with it and adapt it to your needs. I would however suggest to check the Unity documentation out since they often have various small examples for individual methods that are available in the engine.
Preview: https://drive.google.com/file/d/11wcB8gAOLKKg61bwz-vBsfbXvryz2zF0/view
Project .unitypackage: https://drive.google.com/file/d/1wJPEdT$$anonymous$$446pOS_IxkmnAsDrxuZqqQkY7/view
These are 3D versions, my game is 2D and sandbox. I was thinking its a $$anonymous$$or problem and people easily help me.If you played $$anonymous$$ecraft before, you will see dirts become grass after few $$anonymous$$utes, thats what I want to do in 2D...
and after that, check top of the grass, if there is a block, change grass sprite to dirt sprite.
thanks for helping