聲音沒有爲第二次觸摸播放它只爲第一次觸摸播放的聲音只有0.02持續時間,它的MP3播放只用於第一次觸摸,但我必須爲每次點擊它應該覺得汽車加速在統一中添加聲音
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour
{
// The force which is added when the player jumps
// This can be changed in the Inspector window
public Vector2 jumpForce = new Vector2(0, 300);
public AudioClip imp;
public AudioSource clk;
// Update is called once per frame
void Update()
{
// Jump
if (Input.GetMouseButtonDown(0))
{
GetComponent<Rigidbody2D>().velocity = Vector2.zero;
GetComponent<Rigidbody2D>().AddForce(jumpForce);
clk.PlayOneShot (imp, 0.7f);
}
Vector2 screenPosition = Camera.main.WorldToScreenPoint(transform.position);
if (screenPosition.y > Screen.height || screenPosition.y < 0)
{
Die();
}
}
// Die by collision
void OnCollisionEnter2D(Collision2D other)
{
Die();
}
void Die()
{
Application.LoadLevel(0);
}
}
有什麼錯誤?你的調試說什麼?我看到你的班級裏沒有調試代碼 – Martin
他們沒有錯誤 –
它播放automaticaly如果我把它打起來不玩聲音它甚至不發聲 –