Home > Mobile >  How do i access a list thats defined in a different script?
How do i access a list thats defined in a different script?

Time:05-30

So on managerino.cs I have the following code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class managerino : MonoBehaviour
{
    public bool[] availablecardSlots; //the lenght of the list is set on the inspector and all the values begin as true
}

And on my DragDrop.cs script (note that the scripts are not applied to the same gameObject) I want to set one of the elements in availablecardSlots to false, which means I have to be able to modify the list outside of the script where it was created.

I tried this:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DragDrop : MonoBehaviour
{
    int n = 2;
    private void Start()
    {
        managerino = FindObjectOfType<managerino>;
    }

    managerino.availablecardSlots[n] = true;
    Destroy(gameObject);

But its not working I'm getting three errors all about managerino

CodePudding user response:

Because you can not write commands in the body of the class. Move the commands into the method, also you forget () after GetComponent.

private void Start()
{
    managerino = FindObjectOfType<managerino>();
    managerino.availablecardSlots[n] = true;
    Destroy(gameObject);
}

CodePudding user response:

Try to rename your managerino.cs to Managerino.cs and class managerino to class Managerino or you wont able to see it in the inspector.

In c# you can't call methods in the body.

  • Related