Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Is it possible to install multiple tiles with the same direction on a rule tile?

Discussion in '2D' started by Gb-address, Oct 9, 2023.

  1. Gb-address

    Gb-address

    Joined:
    Jul 2, 2023
    Posts:
    1
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using Unity.VisualScripting;
    4. using UnityEngine;
    5. using UnityEngine.Tilemaps;
    6.  
    7. public class Bricks : MonoBehaviour
    8. {
    9.     public Tilemap tilemap;
    10.     public Vector3Int tileposition;
    11.     public Transform PlayerPos;
    12.     public TileBase tileToPlace;
    13.     void Start()
    14.     {
    15.         tilemap = GetComponent<Tilemap>();
    16.         PlayerPos = GetComponent<Transform>();
    17.     }
    18.  
    19.     private void Update()
    20.     {
    21.         if (Input.GetMouseButtonDown(1))
    22.         {
    23.  
    24.             Vector3 mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    25.  
    26.             Vector3Int clickedTilePos = tilemap.WorldToCell(mouseWorldPos);
    27.  
    28.             if (ShouldPlaceTile(clickedTilePos))
    29.             {
    30.                 tilemap.SetTile(clickedTilePos, tileToPlace);
    31.             }
    32.         }
    33.     }
    34.     public void MakeDot(Vector3 pos)
    35.     {
    36.         Vector3Int cellPoition = tilemap.WorldToCell(pos);
    37.  
    38.     }
    39.  
    40.     bool ShouldPlaceTile(Vector3Int tilePos)
    41.     {
    42.  
    43.         if (!IsBlockAbove(tilePos.x, tilePos.y))
    44.         {
    45.             return true;
    46.         }
    47.         else
    48.         {
    49.             return false;
    50.         }
    51.     }
    52.  
    53.     bool IsBlockAbove(int x, int y)
    54.     {
    55.        
    56.         Vector3Int tilePos = new Vector3Int(x, y + 1, 0);
    57.         TileBase tileAbove = tilemap.GetTile(tilePos);
    58.  
    59.        
    60.         if (tileAbove != null)
    61.         {
    62.             return true;
    63.         }
    64.         else
    65.         {
    66.             return false;
    67.         }
    68.     }
    69.  
    70. }

    It doesn't recognize them as the same tile; it gives the feeling of them being separated.
    How can I combine these?
    I need the blocks to change into different ones when destroyed and clicked with the mouse, but they can also be placed in mid-air. I've been struggling with this issue for a long time, and I can't seem to find a solution

    I would really appreciate it if you could provide an answer, please.
     

    Attached Files:

    Last edited: Oct 10, 2023
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,105
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,275
    I have no idea what your question is, but here is how you can get more information, perhaps even figure it out yourself:


    Time to start debugging! Here is how you can begin your exciting new debugging adventures:

    You must find a way to get the information you need in order to reason about what the problem is.

    Once you understand what the problem is, you may begin to reason about a solution to the problem.

    What is often happening in these cases is one of the following:

    - the code you think is executing is not actually executing at all
    - the code is executing far EARLIER or LATER than you think
    - the code is executing far LESS OFTEN than you think
    - the code is executing far MORE OFTEN than you think
    - the code is executing on another GameObject than you think it is
    - you're getting an error or warning and you haven't noticed it in the console window

    To help gain more insight into your problem, I recommend liberally sprinkling
    Debug.Log()
    statements through your code to display information in realtime.

    Doing this should help you answer these types of questions:

    - is this code even running? which parts are running? how often does it run? what order does it run in?
    - what are the names of the GameObjects or Components involved?
    - what are the values of the variables involved? Are they initialized? Are the values reasonable?
    - are you meeting ALL the requirements to receive callbacks such as triggers / colliders (review the documentation)

    Knowing this information will help you reason about the behavior you are seeing.

    You can also supply a second argument to Debug.Log() and when you click the message, it will highlight the object in scene, such as
    Debug.Log("Problem!",this);


    If your problem would benefit from in-scene or in-game visualization, Debug.DrawRay() or Debug.DrawLine() can help you visualize things like rays (used in raycasting) or distances.

    You can also call Debug.Break() to pause the Editor when certain interesting pieces of code run, and then study the scene manually, looking for all the parts, where they are, what scripts are on them, etc.

    You can also call GameObject.CreatePrimitive() to emplace debug-marker-ish objects in the scene at runtime.

    You could also just display various important quantities in UI Text elements to watch them change as you play the game.

    Visit Google for how to see console output from builds. If you are running a mobile device you can also view the console output. Google for how on your particular mobile target, such as this answer for iOS: https://forum.unity.com/threads/how-to-capturing-device-logs-on-ios.529920/ or this answer for Android: https://forum.unity.com/threads/how-to-capturing-device-logs-on-android.528680/

    If you are working in VR, it might be useful to make your on onscreen log output, or integrate one from the asset store, so you can see what is happening as you operate your software.

    Another useful approach is to temporarily strip out everything besides what is necessary to prove your issue. This can simplify and isolate compounding effects of other items in your scene or prefab.

    If your problem is with OnCollision-type functions, print the name of what is passed in!

    Here's an example of putting in a laser-focused Debug.Log() and how that can save you a TON of time wallowing around speculating what might be going wrong:

    https://forum.unity.com/threads/coroutine-missing-hint-and-error.1103197/#post-7100494

    "When in doubt, print it out!(tm)" - Kurt Dekker (and many others)

    Note: the
    print()
    function is an alias for Debug.Log() provided by the MonoBehaviour class.



    How to report your problem productively in the Unity3D forums:

    http://plbm.com/?p=220

    This is the bare minimum of information to report:

    - what you want
    - what you tried
    - what you expected to happen
    - what actually happened, log output, variable values, and especially any errors you see
    - links to documentation you used to cross-check your work (CRITICAL!!!)

    The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven't put effort into finding the documentation, why should we bother putting effort into replying?



    If you post a code snippet, ALWAYS USE CODE TAGS:

    How to use code tags: https://forum.unity.com/threads/using-code-tags-properly.143875/

    - Do not TALK about code without posting it.
    - Do NOT post unformatted code.
    - Do NOT retype code. Use copy/paste properly using code tags.
    - Do NOT post screenshots of code.
    - Do NOT post photographs of code.
    - ONLY post the relevant code, and then refer to it in your discussion.
     
  4. venediklee

    venediklee

    Joined:
    Jul 24, 2017
    Posts:
    202
    No, the first rule that matches (depending on its neighbors) will be placed, the remaining rules, whether they are the same or whether they match that position doesn't matter. So in this one, only the first tile will ever be placed, the second one is useless.

    What you can do is use something like the adjacent rule tile in the happy harvest demo, you would re-do your rules with the adjacent rule tile type(green arrow), then you would create a new tile that only contains the second sprite, put it in the adjacent tiles(red arrow) array and paint the selected position with that new tile when you want a tile to break.
    upload_2023-10-11_14-39-30.png
     
    spiney199 likes this.
  5. enderandpeter

    enderandpeter

    Joined:
    Sep 16, 2015
    Posts:
    7
    Thank you very much for this guide. I want to try this, but for now I decided to just make a new tilemap that is ordered in a layer so that it shows above the rule-generated one which is allowing me to freely edit tiles over it.
     
    venediklee likes this.