Unityでゲームを制作しています。
言語はC#を使用しています。
targetの地点にPlayerがきた時点から音を鳴らしたいのですが、音が出ず困っています。
ゲームオブジェクトであるtargetの位置を取得し、
ゲームオブジェクトであるPlayerがtargetと同じ位置に来たら、
その時点から、他の地点にあるpointオブジェクトから音を鳴らすようにしたいです。
下記のコードを記述したscriptをアタッチするのはPlayerオブジェクトやtargetオブジェクトではなく、AudioSourceをアタッチしているpointオブジェクトです。
targetとplayer、point は3Dオブジェクトで作成しています。
Playerは動かすことができます。
ゲーム内ではPlayerはtargetと物理接触せず、targetをすり抜けます。
解決策をご教示頂きたいです。
using System.Collections; using System.Collections.Generic; using Unity.VisualScripting; using UnityEngine; using UnityEngine.UIElements; using static UnityEditor.PlayerSettings; public class audio : MonoBehaviour { AudioSource audioSource; public GameObject target; public GameObject Player; void Start() { audioSource = this.GetComponent<AudioSource>(); audioSource.Stop(); } void Update() { Transform pos5 = target.transform; Vector3 pos4 = pos5.position; if (Player.transform.position == pos4) { audioSource.Play(); } } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/09/14 10:54