Hey guys! Have this error, and just can’t get what i’ve done wrong.
I’ve read some articles about the same problem, carefully inspect my code, but still cant get it. Please, help
“NullReferenceException: Object reference not set to an instance of an object
CubeEditor.Start () (at Assets/CubeEditor.cs:16)”
So, here’s the script itself:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[ExecuteInEditMode]
public class CubeEditor : MonoBehaviour
{
[SerializeField] [Range(1f, 20f)] float gridSize = 10f;
TextMesh textMesh;
void Start()
{
textMesh = GetComponentInChildren<TextMesh>();
textMesh.text = "TEST";
}
void Update()
{
Vector3 snapPos;
snapPos.x = Mathf.RoundToInt(transform.position.x / gridSize) * gridSize;
snapPos.z = Mathf.RoundToInt(transform.position.z / gridSize) * gridSize;
transform.position = new Vector3(snapPos.x, 0f, snapPos.z);
}
}
And here’s my Unity scene objects etc…