15555人加入学习
(100人评价)
通过实例学习:游戏的存档与读档(Unity 2017.2)

制作完成于2018-1-12

价格 免费

鼠标的位置除以屏幕对应的长或宽信息得到枪的旋转角度,需要研究一下mathf

[展开全文]

//协程控制随机时间内生成怪物

IEnumerator AliveTimer()
    {
        yield return new WaitForSeconds(Random.Range(1, 5));
        ActivateMonster();
    }

[展开全文]

//随机生成怪物,用索引生成

public GameObject[] monstrers;
    public GameObject activeMonster = null;
    void Start()
    {
        foreach ( GameObject   monstrer in monstrers)
        {
            monstrer.SetActive(false);
            monstrer.GetComponent<BoxCollider>().enabled = false;
           
       
        }
        ActivateMonster();
    }
    private void ActivateMonster()
    {
        int index = Random.Range(0, monstrers.Length);
        activeMonster = monstrers[index];
        activeMonster.SetActive(true);
        activeMonster.GetComponent<BoxCollider>().enabled = true;
    }
  
    // Update is called once per frame
[展开全文]

这节课代码可以简写成:

    void Awake()
    {
        int index = PlayerPrefs.GetInt("musicOn", 1);
        if (index==1)
        {
            musicToggle.isOn = true;
        }
        else
        {
            musicToggle.isOn = false;
        }
        MusicSwitch();
    }

比老师的方法简单。

 

[展开全文]

当点击事件在toggle上时,isOn发生改变就调用该方法,而不是根据isOn的值判断

[展开全文]

①两个迭代器(IEnumerator)交叉调用,完成一个生命周期。

[展开全文]

前8个课程都是搭建场景的,未写代码

[展开全文]

05-①背景

②墙

③枪

④target

[展开全文]

再看一遍: 设置手枪的旋转

[展开全文]

各位如果有发生找不到位置等的问题的话,有可能是你打多一个Space等的问题,并非仅有打错字才会发生的,所以请各位先生,小姐们注意会比较好哦

 

[展开全文]

    /// <summary>
    /// 生成怪物
    /// </summary>
    /// <returns></returns>
    IEnumerator AliveTimer()
    {
        while (true) {
            yield return new WaitForSeconds(Random.Range(1, 2));
            Debug.Log("生成");
            ActiceMoster();

            while (true) {
                Debug.Log("检测");
                if (activeMoster == null) {
                    break;
                }
                aliveTime -= Time.deltaTime;
                if (aliveTime < 0) {
                    Debug.Log("死亡");
                    DeActiceMoster();
                }
                yield return null;
            }

        }
    }

[展开全文]

給Target添加一個腳本

把void start和voidUpdate刪掉

public GameObject[]mosters;

public GameObject activateMonster = null;

把四種怪物都拖進腳本

ptivate void Start(){

foreach(GameObject monster in monsters)

{

monster.SetActivate(false);

monster.GetComponent<BoxCollider>.enabled = false;

}

ActivateMonster();

}

private void ActivateMonster()

{

int index = Range(0,monsters.Lenght);

activateMonster = monster[index];

activate.SetActive(true);

activate.GetCompoment<BoxCollider>().enabled = true;

}

[展开全文]

游戏物体的激活与组件的激活不同

得到退出键键盘响应

(Input.GetKeyDown(KeyCode.Escape))

得到鼠标左键摁下的响应

(Input.GetMouseButtonDown(0))

//左键是0,右键是1

[展开全文]

Random.Range(x,y)//随机生成x到y之间的数,不包括y,包括x

协程

[展开全文]

PlayerPrefs.SetInt("score",100);

Float height=183.5f;

 

[展开全文]

授课教师

SIKI学院老师

课程特色

图文(1)
下载资料(1)
视频(34)