- Home /
Is it possible to override the texture component values even though the variable is set to public?
I have a texture issue with a VR whiteboard tutorial. When I attach a texture to a plane in Unity that has the whiteboard.cs script attached, the whiteboard plane defaults to plain white when I press run. The plane is still reactive to the marker in a VR space, but I want to be able to put up a stencil texture/material that allows users to trace it. I've seen the similar issue when the variables are private and not when set to public. Has anyone experienced the same texture GetComponent issue? I'm using Unity 2021.2,10f.
Attached is the object before and after pressing run and the mentioned script.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Whiteboard : MonoBehaviour { public Texture2D texture; public Vector2 textureSize = new Vector2(x:2048, y:2048);
void Start()
{
var r = GetComponent<Renderer>();
texture = new Texture2D(width:(int)textureSize.x, height:(int)textureSize.y);
r.material.mainTexture = texture;
}
}.
[1]: /storage/temp/193683-screenshot-2022-03-09-at-211813-min.png