• 카테고리

    질문 & 답변
  • 세부 분야

    게임 프로그래밍

  • 해결 여부

    미해결

DroneSetting.cs 관련 질문

22.03.19 23:17 작성 조회수 165

2

Drone 환경 만들때 

DroneSetting.cs 스크립트 작성 후 Area 에서 Add Component 에서 Drone Setting 컴포넌트를 추가하니

다음 화면처럼 Drone agent 와 Goal 메뉴가 보이지 않습니다. 

도와 주시면 감사 하겠습니다.

하기는 작성한 DroneSetting.cs 코드 입니다. 

 

 

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

public class DroneSetting : MonoBehaviour
{
    private GameObject DroneAgent;
    private GameObject Goal;

    private Vector3 areaInitPos;
    private Vector3 droneInitPos;
    private Quaternion droneInitRot;

    private Transform AreaTrans;
    private Transform DroneTrans;
    private Transform GoalTrans;

    private Rigidbody DroneAgent_Rigidbody;


    void Start()
    {
        AreaTrans = gameObject.transform;
        DroneTrans = DroneAgent.transform;
        GoalTrans = Goal.transform;

        areaInitPos = AreaTrans.position;
        droneInitPos = DroneTrans.position;
        droneInitRot = DroneTrans.rotation;

        DroneAgent_Rigidbody = DroneAgent.GetComponent<Rigidbody>();

    }

    public void AreaSetting()
    {
        DroneAgent_Rigidbody.velocity = Vector3.zero;
        DroneAgent_Rigidbody.angularVelocity = Vector3.zero;

        DroneTrans.position = droneInitPos;
        DroneTrans.rotation = droneInitRot;

        GoalTrans.position = areaInitPos + new Vector3(Random.Range(-5f, 5f), Random.Range(-5f, 5f), Random.Range(-5f, 5f));
        
    }

}

 

답변 2

·

답변을 작성해보세요.

3

아  두 변수를 public 으로 선언하니 됩니다! 감사합니다! 

강의에는 private 로 되어 있는데 수정이 필요해 보이네요.. 

도와주셔서 감사합니다. 

1

안녕하세요! DroneAgent나 Goal과 같은 GameObject가 인스펙터 윈도우에 외부적으로 나타나게 설정하려면 private이 아니라 public으로 설정해주셔야 합니다. 이에 따라 DroneAgent와 Goal에 대한 코드를 

public GameObject DroneAgent

public GameObject Goal

이렇게 수정하고 다시 한번 확인해주시면 될 듯 합니다! :)