30天轻松学会unity自制游戏-调整摄影机

现在会遇到Boss也会一直往前移动,(要测试可以先把摄影机跟player的这行注解掉)如果不做测试就继续写下去罗…(如果做到这边应该有基本的游戏理解能力…多尝试一些想法,就能改变成自己的游戏罗,网路上很多基本教学可以参考^^)

        //transform.Translate(Vector3.up *1 * Time.deltaTime, Space.World);

现在要做的事情是看到Boss这程序就不要执行,不然就会一直往前移动,先把摄影机跟Player玩家的位置调整好,把Player的自动上移备注掉或删掉

public class PlayerControl : MonoBehaviour
{
    private void Update()
    {
        horizontalMove = Input.GetAxisRaw("Horizontal");
        //transform.Translate(Vector3.up * 1 * Time.deltaTime, Space.World);
    }
}

在Main Camera中间的位置放一个碰撞器(isTrigger打勾),这碰撞器要碰到Boss就停止移动
https://ithelp.ithome.com.tw/upload/images/20210920/20140598iENM12dbnH.png
现在来修改一下Camera Up的程序

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraUp : MonoBehaviour
{
	//设定一个布林值 名叫moveStop预设为false
    bool moveStop = false;

    void Start()
    {
        moveStop = false;
    }

    // Update is called once per frame
    void Update()
    {
		//如果(moveStop不为true的时候执行)
        if(!moveStop)
        transform.Translate(Vector3.up *1 * Time.deltaTime, Space.World);
    }

    private void OnTriggerStay2D(Collider2D collision)
    {
		//如果(碰撞器遇到标签叫"Boss"的执行)
        if (collision.tag == "Boss")
			//让布林moveStop = true
            moveStop = true;
    }
}


现在要改boss的标签,跟直接改敌机一样,新增完记得放上
https://ithelp.ithome.com.tw/upload/images/20210920/20140598m6lNRWmoy5.png
最後摄影机跟Player位置调整好後,把Player拖曳进Main Camera,让Player变摄影机的子物件跟着摄影机
https://ithelp.ithome.com.tw/upload/images/20210920/201405983ALRf8e9AY.png
最後长这样就能执行,摄影机的碰撞器碰到Boss就会停下罗
https://ithelp.ithome.com.tw/upload/images/20210920/201405987d3UGSUdL2.png


<<:  找LeetCode上简单的题目来撑过30天啦(DAY5)

>>:  [D05] 数位影像处理

Javascript档案中使用Django template 变数

在template中我们可以定义javascript变数为djagno变数,如下: <scri...

找寻你的设计灵感、素材及好工具

制作网站前,通常需要找寻相关设计灵感,有时候想破头就是没想法,素材对网页内容来说很重要,好不容易找到...

Day 14 - Rancher - 其他事项

本文将於赛後同步刊登於笔者部落格 有兴趣学习更多 Kubernetes/DevOps/Linux 相...

Day24,试着用rancher交差Dashboard

正文 今天要来一日体验rancher server上的dashboard功能 使用racher2.6...

[Day 29]从零开始学习 JS 的连续-30 Days---网页座标及应用

网页座标及应用 首先怎麽读取与显示座标。 座标的判断依据。 如何动态撷取浏览器宽高。 mousemo...