Node script is shared belowI realized that my problem has nothing to do with tilemap or something so I need to update my question. The NodeCalculateAgain()
In the script works fine whenbelow, I run the game for CalculateDirections()
function in the first time. However, whileFixedUpdate()
function to check and update the game is running, wheninter-node route. So isn't there is a changeway to have this run only when needed?
As you can see in the mapscript, I gave the list specifiedfunction named CalculateAgain()
to a button, for example, and tried it while in the script needsgame, but it didn't work. It didn't update the path that needed to be updated (it should add the necessary elements to the list because the directions of the node whose list is empty are available) but it does not add.
Node gameobject is created It only works with Update or FixedUpdate. But this creates a performance problem and Node script is assigned to this objectnot necessary anyway. Later,I only want it was assigned to "Rule Tile" withwork when the addcross-on of the additional package called "Tilemap Extras". Then, these points were drawn on the tilemap named "Nodes" with the tile palette.
I have made explanations on the sample pictures so that my question does not become complicated and there are no missing partsnode route needs to be updated.
First image:
Second image:
using UnityEngine;
using System.Collections.Generic;
public class Node : MonoBehaviour
{
public List<Vector2> availableDirections = new List<Vector2>();
public LayerMask obstacleLayer;
private void Start()
{
CalculateDirections();
}
publicprivate void CalculateDirectionsFixedUpdate()
{
CalculateDirections();
}
public void CalculateDirections()
{
CheckAvailableDirections(Vector2.up);
CheckAvailableDirections(Vector2.down);
CheckAvailableDirections(Vector2.left);
CheckAvailableDirections(Vector2.right);
Debug.Log("CalculateDirections() FUNC WORKED");
}
privatepublic void CheckAvailableDirections(Vector2 direction)
{
RaycastHit2D hit = Physics2D.BoxCastRaycast(this.transform.position, Vector2direction, 3.one0f, *obstacleLayer); 1
if (hit.5f,collider 0== null)
{
Debug.0fDrawRay(this.transform.position, direction, 6* 3.0f, thisColor.obstacleLayerblue, 30.0f);
Debug.Log("BOXCAST HIT WORKED" this.availableDirections.Add(direction);
if}
(hit.collider == null) else
{
Debug.DrawRay(this.availableDirectionstransform.Add(position, direction * 3.0f, Color.yellow, 30.0f);
Debug.Log("ADDED"COLLIDER LIST"ÇALIŞMADI");
}
}
/*
public void CalculateAgain()
{
CalculateDirections();
}
*/
}