using UnityEngine;
using System.Collections;
/// <summary>
/// 实现的功能:就是战斗按钮被按下,随后主角攻击怪物,怪物攻击主角,如果整个
/// 战斗都没结束,这里用isFightEnd判断,则战斗继续执行,否则停止
/// </summary>
public class zTest : MonoBehaviour
{
private int i = 0;
//判断是否整个战斗停止
private bool isFightEnd = false;
//判断战斗按钮是否被按下
private bool isFighting = false;
void Update()
{
if (isFightEnd != true)
{
StartCoroutine(test());
}
}
IEnumerator test()
{
//没有按下战斗按钮
if (isFighting == false)
{
yield return 0;
}
else
{
//主角攻击
Debug.Log("role have attacked!!!!!!");
//怪物攻击
Debug.Log("monster have attacked!!!!");
init();
yield return 0;
}
}
void OnGUI()
{
if (GUILayout.Button("START"))
{
isFightEnd = false;
isFighting = false;
}
if (GUILayout.Button("STOP"))
{
isFightEnd = true;
}
if (GUILayout.Button("FIGHT"))
{
isFighting = true;
}
}
void init()
{
isFighting = false;
}
}
using System.Collections;
/// <summary>
/// 实现的功能:就是战斗按钮被按下,随后主角攻击怪物,怪物攻击主角,如果整个
/// 战斗都没结束,这里用isFightEnd判断,则战斗继续执行,否则停止
/// </summary>
public class zTest : MonoBehaviour
{
private int i = 0;
//判断是否整个战斗停止
private bool isFightEnd = false;
//判断战斗按钮是否被按下
private bool isFighting = false;
void Update()
{
if (isFightEnd != true)
{
StartCoroutine(test());
}
}
IEnumerator test()
{
//没有按下战斗按钮
if (isFighting == false)
{
yield return 0;
}
else
{
//主角攻击
Debug.Log("role have attacked!!!!!!");
//怪物攻击
Debug.Log("monster have attacked!!!!");
init();
yield return 0;
}
}
void OnGUI()
{
if (GUILayout.Button("START"))
{
isFightEnd = false;
isFighting = false;
}
if (GUILayout.Button("STOP"))
{
isFightEnd = true;
}
if (GUILayout.Button("FIGHT"))
{
isFighting = true;
}
}
void init()
{
isFighting = false;
}
}