Как правильнее сделать оперирование переменной из одного скрипта в другом?

Имеется вот такой код:


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

public class GrabbableFlowerBehavior : MonoBehaviour
{
    private GameObject Player;
    GameObject go = GameObject.Find(Player);
    Player PCntrl = go.GetComponent<FlowerCount>();
    public int FC = PCntrl.FlowerCount;
    private GameObject GrabbableFlower;
    private float f = 0.0f;
    void OnTriggerEnter2D(Collider2D other)

    {
        if (other.tag == "Player")
        {
            FC++;
            Destroy(GrabbableFlower, .0f);

        }

    }

}

Я не понимаю, почему Unity выдаёт следующую ошибку:

Assets\scripts\GrabbableFlowerBehavior.cs(9,5): error CS0246: The type or namespace name 'Player' could not be found (are you missing a using directive or an assembly reference?)


Ответы (1 шт):

Автор решения: Максим Фисман

GameObject.Find ищет объект по имени, имя это строка, а строки заключаются в кавычки. Поэтому мы замените GameObject.Find(Player) на GameObject.Find("Player")

→ Ссылка