-1

Hello i have 3d Sphere and i would like to change the interactable property by code, but i have an error Object reference not set to an instance of an object when i try to set the boolean value. Please note that the script is attached to the 3d Object

this is my code

using System.Collections;
using UnityEngine;

public class Drag : MonoBehaviour
{
    public Button obj;

    void Awake()
    {
        Button obj = GameObject.Find("Sphere").GetComponent<Button>();
    }

    void Start()
    {
       this.obj.interactable = false;

    } 
}

enter image description here

thanks in advance

derHugo
  • 83,094
  • 9
  • 75
  • 115
Gelso77
  • 1,763
  • 6
  • 30
  • 47
  • Does this answer your question? [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – BugFinder Jan 26 '22 at 23:41
  • Is this object called “Sphere” you don’t show a component called Button on it. Either would result in that error. – BugFinder Jan 26 '22 at 23:43
  • @BugFinder, the GameObject sphere seems doesn't have the property interactable. – Gelso77 Jan 27 '22 at 08:38
  • Please use the correct tags! Note that [`[unityscript]`](https://stackoverflow.com/tags/unityscript/info) is or better **was** a custom JavaScript flavor-like language used in early Unity versions and is **long deprecated** by now. Your code is in `c#` ... – derHugo Jan 31 '22 at 15:24

1 Answers1

0

From your post i've understood that you want to disable Interactable Component

public Interactable interactable;

void Awake()
{
    interactable = GetComponent<Interactable>();
}

void Start()
{
   interactable.enabled = false;
} 
R1nge
  • 26
  • 4