我不断收到此错误(CS0106:修饰符“私有”对此项目无效)并且需要一些帮助。我正在尝试为我的游戏制作一个随机对象生成器,但由于我仍然是新手编码器,我似乎不知道如何解决这个问题。你能帮忙的话,我会很高兴
这是我使用的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class deployAsteroids : MonoBehaviour
{
public GameObject asteroidPrefab;
public float respawnTime = 1.0f;
void Start()
{
screenBounds = Camera.main.ScreenToWorldPoint(new Vector3(screenBounds.x, screenBounds.y, Camera.main.transform.position.z));
StartCorountine(asteroidWave());
private void spawnEnemy()
{
GameObject a = Instantiate(asteroidPrefab) as GameObject;
a.transform.position = new Vector2(Random.Range(-screenBounds.x, screenBounds.x), screenBounds.y * -2);
}
IEnumerator astroidWave()
{
while (true)
{
yield return new WaitForSeconds(respawnTime);
spawnEnemy();
}
}
}
每当出现编译器错误时,您应该考虑的第一件事就是在搜索引擎中查找错误代码。从CS0106 https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0106提供了规则。第四点对此很清楚。
本地函数不允许使用访问修饰符。本地函数始终是私有的。
您有两个选择:
- 将方法移到父方法之外(
Start()
)。如果将在多个地方使用,这是典型的场景。
- 删除修改器
private
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)