Unity语法错误当我按空格键时,LaserSound无法播放吗?

时间:2019-02-13 00:28:43

标签: c# unity3d

我试图让敌舰射击玩家,将玩家标记为玩家 我收到一个错误:Assets / Scripts / EnemyAttack.cs(11,13):错误CS0246:找不到类型或名称空间名称“ EnemyAtack”。您是否缺少装配参考?我尝试为敌人的攻击创建一个班级,但没有成功。任何反馈表示赞赏。

 using System;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;


 public class EnemyAttack : MonoBehaviour
 {
[SerializeField] GameObject[] enemyGuns;

// Start is called before the first frame update
void Start()
{
    AddSphereCollider();
}

private void AddSphereCollider()
{
Collider sphereCollider = gameObject.AddComponent<SphereCollider>();
    sphereCollider.isTrigger = false;
}

void OnCollisionEnter(Collision col)
{
    if (col.gameObject.name == "player")
    {
        Destroy(col.gameObject);
    }
}
}

2 个答案:

答案 0 :(得分:0)

Stop()和PlayOneShot()都是与AudioSource类关联的函数。

AudioSources用于播放AudioClip,在这种情况下,您需要为单声道行为添加一个AudioSource引用,并向预制件添加一个AudioSource,然后链接该引用并在AudioSource上调用PlayOneShot()和Stop()函数

另一个问题是您的AudioClip名为LaserSound,而Monobehaviour也称为LaserSound。 重命名一个。

答案 1 :(得分:0)

更改

[SerializeField] private AudioClip LaserSound;

[SerializeField] private AudioClip laserSound;

,那应该可以。 “ AudioClip LaserSound”基本上相当于“ Classname AnotherClassname”