A suggestion

what if i want to put a vector instead of the sentence camera.main.transform.position
if i want to get the camera position using vector 2
how can i do it

From the the Unity Scripting Reference on AudioSource

You can replace our camera position with the target vector2 you with to use.


using UnityEngine;

public class Block : MonoBehaviour {
    public AudioClip clip;

    void Start() {
        // AudioSource.PlayClipAtPoint(breakSound, Camera.main.transform.position);
        AudioSource.PlayClipAtPoint(clip, new Vector2(5, 1));
        Destroy(gameObject);
    }
}

thnx for the answer :smiley:

Le mer. 20 févr. 2019 à 10:25, Sowed Castelli via GameDev.tv gamedev@discoursemail.com a écrit :

1 Like

for vector2:
AudioSource.PlayClipAtPoint(breakSound, new Vector2(Camera.main.transform.position.x, Camera.main.transform.position.y));

using vector3 is good approach, because it in vector 2 you cannot get z position of the camera. This can lead to less volume of clip
In vector3:
AudioSource.PlayClipAtPoint(breakSound, new Vector3(Camera.main.transform.position.x, Camera.main.transform.position.y, Camera.main.transform.position.z));

just write it this way:-
AudioSource.playClipAtPoint(BreakSound, transform.position);
transform.position here refers to position of the block and as the block is a prefab it will be applied to every block and transform.position will be according to the respective block

so the clip will be played at the point(position)of the block

Privacy & Terms