0
我有以下的C#代碼:哪裏可以放置InvokeRepeating?
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);
}
我收到以下消息的錯誤:
error CS1519: Unexpected symbol `EnemySpawn' in class, struct, or interface member declaration
公共變量(動畫和Rigidbody2d)都設置正確
應該在哪裏移動InvokeRepeating?我搜索了一些答案;我在開始和EnemySpawn結束時移動了InvokeRepeating。結果是每幀的敵人越來越多。 這個問題的解決方案是什麼?
其中'InvokeRepeating'其實叫什麼名字?它看起來不像它的方法。 –
把它放在'Start()'裏面 – Fattie