2017-04-30 1 views
1

안녕하세요. 내 개체에 오디오 소스 구성 요소가 연결되어 있습니다. 나는 또한 here에서 스크립트를 복사하여 내 개체에 첨부했습니다. 내 스크립트에 오디오를 사용하려고하면Unity3D AudioSource가 객체에 연결되지 않습니까?

using UnityEngine; 
using System.Collections; 

[RequireComponent(typeof(AudioSource))] 
public class ExampleClass : MonoBehaviour 
{ 
    public AudioClip impact; 
    AudioSource audio; 

    void Start() 
    { 
     audio = GetComponent<AudioSource>(); 
    } 

    public void play_sound() 
    { 
     audio.PlayOneShot(impact, 0.7F); 
    } 
} 

하지만 나는 그것이 enter image description here

문제가 무엇 잘라 얻을?

답변

1

당신은 같은 그들에 선언 몇 가지 변수가있는 Component에서 다음 Behaviour 및 상속 MonoBehaviour에서 내재되어이 모든를 더 이상 사용되지 않으므로 최근에 사용될 수 있습니다

public Component animation { get; } 
public Component audio { get; } 
public Component camera { get; } 
public Component collider { get; } 
public Component collider2D { get; } 
public Component constantForce { get; } 
public Component guiElement { get; } 
public Component guiText { get; } 
public Component guiTexture { get; } 
public Component hingeJoint { get; } 
public Component light { get; } 
public Component networkView { get; } 
public Component particleEmitter { get; 
public Component particleSystem { get; } 
public Component renderer { get; } 
public Component rigidbody { get; } 
public Component rigidbody2D { get; } 

Unity 버전. 나는 유니티 5에서 비추천이라고 생각합니다. 연결된 문서가 아직 업데이트되지 않았습니다. 자세한 내용은 this 게시물을 참조하십시오.

오디오 변수의 이름을 다른 것으로 바꾸면 모든 것이 잘 작동합니다.

public AudioClip impact; 
AudioSource myAudio; 

void Start() 
{ 
    myAudio = GetComponent<AudioSource>(); 
} 

public void play_sound() 
{ 
    myAudio.PlayOneShot(impact, 0.7F); 
} 
관련 문제