Search Unity

How to change setings of a trough scripting attach component

Discussion in 'Scripting' started by beltmanmarc, Mar 29, 2013.

  1. beltmanmarc

    beltmanmarc

    Joined:
    Aug 19, 2012
    Posts:
    8
    I have attached a "audiosource" component to my camera through scripting. Can someone tell me how to link a soundfile to this component. In other words, how can i modify its settetings through scripting

    public static void UseExistingOrCreateMainCamera()
    {
    GameObject tempCamera;
    GameObject targetLookAt;
    TP_camera myCamera;

    if (Camera.mainCamera != null)
    {
    tempCamera = Camera.mainCamera.gameObject;
    }
    else
    {
    tempCamera = new GameObject ("Main Camera");
    tempCamera.AddComponent("Camera");
    tempCamera.AddComponent("GUILayer");
    tempCamera.AddComponent("AudioSource");
    tempCamera.tag = "MainCamera";
    }
     
  2. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    945