unity C#에 관한 질문입니다

조회수 433회

현재 unity로 2D게임을 만드는 중인데 한 cs파일에 있는 변수를 다른 cs 파일에서 사용하고 싶은데 어떻게 해야하나요?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameDirector : MonoBehaviour
{
    GameObject angerGauge;
    GameObject gaugePercent;
    GameObject speed;
    GameObject life_1;
    GameObject life_2;
    GameObject life_3;
    float per = 0.3f;
    int life = 0;
    int Audispeed=20;

    // Start is called before the first frame update
    void Start()
    {
        this.angerGauge = GameObject.Find("angerGauge");
        this.gaugePercent = GameObject.Find("gaugePercent");
        this.speed = GameObject.Find("speed");
        this.life_1 = GameObject.Find("life_1");
        this.life_2 = GameObject.Find("life_2");
        this.life_3 = GameObject.Find("life_3");
        this.angerGauge.GetComponent<Image>().fillAmount = 0.3f;
    }

이 코드에 있는 Audispeed 변수를

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


public class road_move : MonoBehaviour
{
    int speed;
    public int startIndex;
    public int endIndex;
    public Transform[] sprites;
    GameObject GameDirector;

    float viewHeight;
    private void Awake()
    {
        viewHeight = Camera.main.orthographicSize*2;
    }

    void Start()
    {
        this.GameDirector = GameObject.Find("GameDirector");
    }

    void Update()
    {
         speed = GameDirector.Audispeed;

이 코드의 speed 변수에 넣어 사용하고 싶습니다..

  • 클래스의 캡슐화와 가시성을 공부해보세요. 정영훈 2020.5.11 23:27

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)