C# And Unity
Script에서 상위 attribute 접근시 오류 현상
-TED-
2011. 5. 3. 08:42
상위에 audio 객체에 접근할수 있지만 사용할 수 없다고 나옵니다.
반드시 아래와 같이 선언해 줘야 합니다.
참조 오류가 나면 해당 스크립트를 제거 하고 Editor에서 재등록을 해주어야 인식합니다.
아래를 참고하세요.
[RequireComponent(typeof(AudioSource))]
public class CreateCube : MonoBehaviour
{
public GameObject prefab;
public AudioClip clip;
// Use this for initialization
void Start()
{
print("Start CreateCube");
}
// Update is called once per frame
void Update()
{
// 예> Space키를 띌경우,
if (Input.GetButtonUp("Jump"))
{
//0,0,0 좌표에서 사운드 플레이
audio.volume = 1f;
audio.PlayOneShot(clip);
//AudioSource.PlayClipAtPoint(clip, new Vector3(-100, 14, 5));
Debug.Log("Input- Jump");
// 새로운 Object 생성
GameObject go = (GameObject)Instantiate(prefab, transform.position, transform.rotation);
//z축으로 1 unit 이동 per 1 second
go.transform.Translate(100*Vector3.up * Time.deltaTime);
//힘 가하기
go.rigidbody.AddForce(transform.forward * 1000);
}
}
}