unity官方demo学习之Stealth(七)激光门

本文介绍了在Unity中实现激光门开关的详细步骤,包括添加激光门模型、控制激光门开关的脚本DoneLaserBlinking、检测玩家碰撞的脚本DoneLaserPlayerDetection、设置开关模型及其交互逻辑的脚本DoneLaserSwitchDeactivation,并进行了场景布置、灯光烘焙等操作。通过这些步骤,实现了游戏中的激光门功能。
摘要由CSDN通过智能技术生成
七,激光门

1,将models中的fx_laserFence_lasers拖到层级视图中,设置如图009,并且方便管理编号_001


2,为其添加box collider组件,勾选 is trigger
3,为其添加音频组件,将laser_hum拖进去,勾选loop,3d中的Min Distance设为1.8
4,添加light组件,设置颜色(255,40,0),range改成5,intensity改为0.6,lightmapping设为 realtime only(这样当门关上时不会
重新渲染此light使光还留在场景中)

5,添加脚本DoneLaserBlinking 控制激光门开关

using UnityEngine;
using System.Collections;

public class DoneLaserBlinking : MonoBehaviour
{
	public float onTime;			// Amount of time in seconds the laser is on for.
	public float offTime;			// Amount of time in seconds the laser is off for.
	
	
	private float timer;			// Timer to time the laser blinking.
	
	
	void Update ()
	{
		// Increment the timer by the amount of time since the last frame.
        timer += Time.deltaTime;
		
		// If the beam is on and the onTime has been reached...
        if(renderer.enabled && timer >= onTime)
			// Switch the beam.
            SwitchBeam();
		
		// If the beam is off and the offTime has been reached...
        if(!renderer.enabled && timer >= offTime)
			// Switch the beam.
            SwitchBeam();
	}
	
	
	void SwitchBeam ()
	{
		// Reset the timer.
		timer = 0f;
		
		// Switch whether the beam and light are on or off.
	    renderer.enabled =
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值