Having this error
I have tried many options to pass the reference to null such as:
But it didn't work. I know it's a simple error, but I'm new in coding. A little help will be appreciated a lot.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
public class Paintable : MonoBehaviour {
public GameObject Brush;
public float BrushSize = 0.1f;
public RenderTexture RTexture;
void Update () {
if (Input.GetMouseButton(0))
{
// error is in this line
var Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if(Physics.Raycast(Ray, out hit))
{
var go = Instantiate(Brush, hit.point + Vector3.up * 0.1f, Quaternion.identity, transform);
go.transform.localScale = Vector3.one * BrushSize;
}
}
}
NullReferenceException: Object reference not set to an instance of an object Paintable.Update () (at Assets/Datafiles/Scripts/Paintable.cs:23)
It is giving me error when I start a play mode in unity to draw on a plane with a brush.