我在Unity中播放音频片段时遇到了问题。
当检测到玩家时,我希望我的鲨鱼能够发出“咬”的声音,但声音却变形了。
其余的代码都按预期运行。
请问我能够进行代码审查并提供建议吗?
我可能在哪里出了错(调用音频源播放时)?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Shark2Controller : MonoBehaviour {
public Transform leftPoint;
public Transform rightPoint;
public float startSpeed;
public float swimSpeed;
private Rigidbody2D myRigidBody;
public bool swimmingRight;
public float superSpeed;
public Transform puntoA;
public Transform puntoB;
public LayerMask whatIsPlayer;
public bool playerDetected;
private Animator myAnim;
public AudioSource bite;
// Use this for initialization
void Start ()
{
myRigidBody = GetComponent<Rigidbody2D> ();
myAnim = GetComponent<Animator>();
swimSpeed = startSpeed;
}
// Update is called once per frame
void Update ()
{
playerDetected = Physics2D.OverlapArea (puntoA.position, puntoB.position, whatIsPlayer);
myAnim.SetBool ("Player Detected", playerDetected);
if (playerDetected)
{
swimSpeed = superSpeed;
bite.Play ();
}
if (swimmingRight && transform.position.x > rightPoint.position.x)
{
swimmingRight = false;
}
if (!swimmingRight && transform.position.x < leftPoint.position.x)
{
swimmingRight = true;
}
if (swimmingRight)
{
myRigidBody.velocity = new Vector3 (swimSpeed, myRigidBody.velocity.y, 0f);
transform.localScale = new Vector3 (1f, 1f, 1f);
}
else
{
myRigidBody.velocity = new Vector3 (-swimSpeed, myRigidBody.velocity.y, 0f);
transform.localScale = new Vector3 (-1f, 1f, 1f);
}
}
public void ResetShark2Speed()
{
swimSpeed = startSpeed;
}
}
bite.Play();
应该在每个帧更新时触发吗?如果您的FPS为60,您真的想让bite
每秒播放60次吗?那听起来不太好,我期望会有(可能的)嗡嗡声/卡顿的噪音……也许这就是你所说的变形? - VC.One