using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class soundspPlay : MonoBehaviour
{
public AudioSource firstsound;
public AudioSource secondsound;
public bool alreadyPlayed = false;
void OnTriggerEnter(Collider collider)
{
if (collider.gameObject.tag == "Player" , !alreadyPlayed)
{
firstsound.Play();
secondsound.Play();
alreadyPlayed = true;
}
}
}
我需要两种声音在触发器上播放,但我只想播放一次,并且只有在带有“播放器”标签的对象进入时才播放。
不,语法是:
if (collider.gameObject.tag == "Player" && !alreadyPlayed)
或
if (collider.gameObject.tag == "Player" || !alreadyPlayed)
&&
要求两个操作数都为真,||
只需要一个操作数为真。
true && true == true
true && false == false
false && false == false
true || true == true
true || false == true
false || false == false