vo
vo
本课程全部学习,感谢Sandy老师提供的资源和教学!
获取怪物
激活{随机激活}
我就是来听小姐姐说话的。。。
//创建一个StreamReader,用来读取流
StreamReader sr = new StreamReader(filePath);
//将读取到的流赋值给jsonStr
string jsonStr= sr.ReadToEnd();
//关闭
sr.Close();
//将字符串jsonStr转换为Save对象
Save save =JsonMapper.ToObject<Save>(jsonStr);
读取
//反序列化过程
//创建一个二进制格式化程序
BinaryFormatter bf = new BinaryFormatter();
//打开一个文件流
FileStream fileStream = File.Open(Applicaton.dataPath + "/StreamingFile" + "/byBin.txt",FileMode.Open);
//调用格式化程序的反序列化方法,将文件流转换成一个Save对象
Save save = (Save)bf.Deserialize(fileStream);
//关闭流文件
fileStream.Close();
协程是一个分部执行
IEnumberator
第17 集比较难
[System.Serializble]
不会反复DIAOYON
using System.Collections; using System.Collections.Generic; using UnityEngine; public class TargetManager : MonoBehaviour { public GameObject[] monsters; public GameObject activeMonster = null; private void Start() { foreach(GameObject monster in monsters) { monster.GetComponent().enabled = false; monster.SetActive(false); } ActivateMonster(); } private void ActivateMonster() { int index = Random.Range(0,monsters.Length); activeMonster = monsters[index]; activeMonster.SetActive(true); activeMonster.GetComponent().enabled = true; } }
乖孙儿
public GameObject[ ] monster;
public GameObject activateMonster=null;
private void ActivateMonster(){
int index = Random.Range(0,monsters.Length);
activateMonster=monsters[index];
activateMonster.SetActive(true);
activateMonster.GetComponent<BoxCollider>().enabled=true;
}
//协程
IEnumerator AliveTimer()
{
yield return new WaitForSeconds(Random.Range(1, 5));
ActivateMonster();
}
*
if(Input.GetMouseButtonDown(0))
{
GameObject Bullet = GameObject.Instantiate(bullet, firePos.position, Quaternion.identity);
}
05-①背景
②墙
③枪
④target
//施加一个力给子弹,让子弹移动
Bullet.GetComponent<Rigidbody>().AddForce(transform.forward * 3000);
//播放开火动画并初始化shootTimer
gameObject.GetComponent<Animation>().Play();
shootTimer = 0;
void Start()
{
StartCoroutine("DestroyMyself");
}
IEnumerator DestroyMyself()
{
//等待3秒之后销毁自身
yield return new WaitForSeconds(3);
Destroy(this.gameObject);
}
IEnumerator AliveTimer()
{
//开始的函数
yield return new WaitForSeconds(Random.Range(1,5)); // return后可有其他返回值,常用的是控制时间等待的函数
//剩下的函数
}
StartCoroutine("AliveTimer");//开始一个协程,里面填协程名
协程:分部执行,遇到条件(yield return语句)时会挂起,知道条件满足后才会被唤醒继续执行后面的代码。可控制程序运行的时间。