Home > database >  Unity how change the intractable property with the code
Unity how change the intractable property with the code

Time:01-29

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

CodePudding user response:

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;
} 
  •  Tags:  
  • Related