【3D技术宅公社】XR数字艺术论坛  XR技术讨论 XR互动电影 定格动画

 找回密码
 立即注册

QQ登录

只需一步,快速开始

调查问卷
论坛即将给大家带来全新的技术服务,面向三围图形学、游戏、动画的全新服务论坛升级为UTF8版本后,中文用户名和用户密码中有中文的都无法登陆,请发邮件到324007255(at)QQ.com联系手动修改密码

3D技术论坛将以计算机图形学为核心,面向教育 推出国内的三维教育引擎该项目在持续研发当中,感谢大家的关注。

查看: 1535|回复: 0

4-7 CCTV Cameras 游戏里的监控器

[复制链接]
发表于 2013-9-30 22:36:07 | 显示全部楼层 |阅读模式
设置游戏中的警告监控器,使用监控器的模型创建巡视动画。这段教程中讲解了如何创建监视器、如何创建监视器的摆头动画,如何创建监视器的视野以及发射的红色激光束。
监视器的代码相对比较简单,即当玩家进入摄像机视野就触发警报,然后将全局的一个焦点聚焦到玩家上。
CCTVPlayerDetection
C#脚本
  1. using UnityEngine;
  2. using System.Collections;

  3. public class CCTVPlayerDetection : MonoBehaviour
  4. {
  5.     private GameObject player;                          // 指向玩家的变量.
  6.     private LastPlayerSighting lastPlayerSighting;      // 指向玩家的视野的全局变量.

  7.    
  8.     void Awake ()
  9.     {
  10.         // 设置变量.
  11.         player = GameObject.FindGameObjectWithTag(Tags.player);
  12.         lastPlayerSighting = GameObject.FindGameObjectWithTag(Tags.gameController).GetComponent<LastPlayerSighting>();
  13.     }
  14.    
  15.    
  16.     void OnTriggerStay (Collider other)
  17.     {
  18.         // 如果闯进碰撞检测区域的玩家...
  19.         if(other.gameObject == player)
  20.         {
  21.             // ... 从摄像机发射一个射线射向玩家.
  22.             Vector3 relPlayerPos = player.transform.position - transform.position;
  23.             RaycastHit hit;
  24.             
  25.             if(Physics.Raycast(transform.position, relPlayerPos, out hit))
  26.                 // 如果射线碰上了玩家...
  27.                 if(hit.collider.gameObject == player)
  28.                     // ... 将聚焦点设在玩家身上.
  29.                     lastPlayerSighting.position = player.transform.position;
  30.         }
  31.     }
  32. }
复制代码
JS脚本
  1. #pragma strict

  2. private var player : GameObject;                                // Reference to the player.
  3. private var lastPlayerSighting : LastPlayerSighting;        // Reference to the global last sighting of the player.


  4. function Awake ()
  5. {
  6.     // Setting up the references.
  7.     player = GameObject.FindGameObjectWithTag(Tags.player);
  8.     lastPlayerSighting = GameObject.FindGameObjectWithTag(Tags.gameController).GetComponent(LastPlayerSighting);
  9. }


  10. function OnTriggerStay (other : Collider)
  11. {
  12.     // If the colliding gameobject is the player...
  13.     if(other.gameObject == player)
  14.     {
  15.         // ... raycast from the camera towards the player.
  16.         var relPlayerPos : Vector3 = player.transform.position - transform.position;
  17.         var hit : RaycastHit;
  18.         
  19.         if(Physics.Raycast(transform.position, relPlayerPos, hit))
  20.             // If the raycast hits the player...
  21.             if(hit.collider.gameObject == player)
  22.                 // ... set the last global sighting of the player to the player's position.
  23.                 lastPlayerSighting.position = player.transform.position;
  24.     }
  25. }
复制代码
相关知识:Light probes  灯光探测器

手机版|小黑屋|3D数字艺术论坛 ( 沪ICP备14023054号 )

GMT+8, 2024-5-23 19:01

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表