【发布时间】:2016-02-13 16:23:43
【问题描述】:
我有以下 C# 代码:
using UnityEngine;
using System.Collections;
public class Hero : MonoBehaviour {
float speed = 2f;
bool hero_up = false;
bool hero_down = false;
bool hero_left = false;
bool hero_right = false;
public Animator animator;
public Rigidbody2D rbEnemy;
// Use this for initialization
void Start ()
{
animator = GetComponent<Animator> ();
EnemySpawn ();
}
void EnemySpawn()
{
Rigidbody2D EnemyInstance;
EnemyInstance = Instantiate(rbEnemy, new Vector3(Random.Range (2f, 8f), Random.Range (-4f, 4f) ,0f), Quaternion.Euler(new Vector3(0f,0f,0f))) as Rigidbody2D;
}
// Update is called once per frame
InvokeRepeating("EnemySpawn", 3, 3);
}
我收到以下消息错误:
错误 CS1519:类、结构或接口成员声明中出现意外符号“EnemySpawn”
正确设置公共变量(Animator 和 Rigidbody2d)
应该将 InvokeRepeating 移到哪里?我搜索了一些答案;我将 InvokeRepeating 移到 Start 和 EnemySpawn 的末尾。结果是每帧的敌人数量越来越多。 这个问题的解决方法是什么?
【问题讨论】:
-
InvokeRepeating实际调用在哪里?它看起来不像它的方法。 -
放入
Start()