c# - 'public / static' 修饰符对此项无效
问题描述
我创建了一个脚本来在游戏中添加声音,比如跳跃和击打,我有一个我无法解决的错误仍然说The modifier 'public' is not valid for this item
,我统一说,我的方式The static modifier is not valid for this item
可以帮助我吗?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SoundManagerScript : MonoBehaviour
{
public static AudioClip Hit_HurtSound, Jump2Sound;
static AudioSource audioSrc;
// Start is called before the first frame update
void Start()
{
Hit_HurtSound = Resources.Load<AudiotClip> ("Hit_Hurt");
Jump2Sound = Resources.Load<AudiotClip> ("Jump2");
audioSrc = GetComponent<AudioSource> ();
}
// Update is called once per frame
void Update()
{
public static void PlaySound (string clip)
{
switch (clip)
{
case "Jump2":
audioSrc.PlayOneShot(Jump2Sound);
break;
case "Hit_Hurt":
audioSrc.PlayOneShot(Hit_HurtSound);
break;
}
}
}
}
解决方案
就像@DavidG 在他的评论中所说,你不能有一个方法和一个方法。它应该如下所示:
public static void PlaySound (string clip)
{
switch (clip)
{
case "Jump2":
audioSrc.PlayOneShot(Jump2Sound);
break;
case "Hit_Hurt":
audioSrc.PlayOneShot(Hit_HurtSound);
break;
}
}
您必须删除此行(及其}
)
void Update()
{
推荐阅读
- algorithm - 求 B-Tree 存储键数的度数?
- mongodb - Mongodb如何全部插入或更新?
- javascript - 更改为功能掩码
- java - 无法获取 Derby 10.15 的驱动程序实例
- gpflow - 用空 X 和 Y 初始化 GPFlow 模型
- python - python3:文本文件到电子邮件正文
- java - 使用 Asynctask (ANDROID) 解决 ConcurrentModificationException 问题
- facebook-graph-api - 有什么方法可以使用 Facebook SDK 创建 Facebook 事件?
- php - 图表不加载:带有 PHP 的 jQuery HighchartTable 插件将表格数据转换为图表
- angular - 从来自后端响应的对象设置表单状态