Hi,
I’ve been having some problems now that we are trying to de-couple the editor from the waypoints (or in my case tiles) for pathfinding. whenever I try to call the tile(waypoint) script class from the CubeEditor script its giving me a null reference exception that the instance of the script does not exist.
(for reference I’m in unity 2018.3.5f1)
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//[ExecuteAlways]
[ExecuteInEditMode]
[SelectionBase]
[RequireComponent(typeof(Tile))]
public class CubeEditor : MonoBehaviour
{
//[SerializeField] Tile tile;
Tile tile;
private void Awake()
{
tile = GetComponent<Tile>();
}
// Update is called once per frame
void Update()
{
SnaptoPlace();
UpdateLabel();
}
private void SnaptoPlace()
{
int tileSize = tile.GetTileScale();
transform.position = new Vector3(
tile.GetTilePos().x * tileSize,
0f,
tile.GetTilePos().y * tileSize
);
}
private void UpdateLabel()
{
int tileSize = tile.GetTileScale();
string coordinates =
tile.GetTilePos().x / tileSize +
"," +
tile.GetTilePos().y / tileSize;
TextMesh textMesh = GetComponentInChildren<TextMesh>();
textMesh.text = coordinates;
gameObject.name = "Tile (" + coordinates + ")";
}
}