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

 找回密码
 立即注册

QQ登录

只需一步,快速开始

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

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

查看: 1613|回复: 0

6-2 The Key 钥匙的逻辑

[复制链接]
发表于 2013-10-2 08:21:28 | 显示全部楼层 |阅读模式
设置玩家通关需要的钥匙的逻辑 未标题-2.jpg
KeyPickup
C#
  1. using UnityEngine;
  2. using System.Collections;

  3. public class KeyPickup : MonoBehaviour
  4. {
  5.     public AudioClip keyGrab;                       // Audioclip to play when the key is picked up.
  6.    
  7.    
  8.     private GameObject player;                      // Reference to the player.
  9.     private PlayerInventory playerInventory;        // Reference to the player's inventory.
  10.    
  11.    
  12.     void Awake ()
  13.     {
  14.         // Setting up the references.
  15.         player = GameObject.FindGameObjectWithTag(Tags.player);
  16.         playerInventory = player.GetComponent<PlayerInventory>();
  17.     }
  18.    
  19.    
  20.     void OnTriggerEnter (Collider other)
  21.     {
  22.         // If the colliding gameobject is the player...
  23.         if(other.gameObject == player)
  24.         {
  25.             // ... play the clip at the position of the key...
  26.             AudioSource.PlayClipAtPoint(keyGrab, transform.position);
  27.             
  28.             // ... the player has a key ...
  29.             playerInventory.hasKey = true;
  30.             
  31.             // ... and destroy this gameobject.
  32.             Destroy(gameObject);
  33.         }
  34.     }
  35. }
复制代码
JS
  1. #pragma strict

  2. public var keyGrab : AudioClip;                         // Audioclip to play when the key is picked up.


  3. private var player : GameObject;                        // Reference to the player.
  4. private var playerInventory : PlayerInventory;      // Reference to the player's inventory.


  5. function Awake ()
  6. {
  7.     // Setting up the references.
  8.     player = GameObject.FindGameObjectWithTag(Tags.player);
  9.     playerInventory = player.GetComponent(PlayerInventory);
  10. }


  11. function OnTriggerEnter (other : Collider)
  12. {
  13.     // If the colliding gameobject is the player...
  14.     if(other.gameObject == player)
  15.     {
  16.         // ... play the clip at the position of the key...
  17.         AudioSource.PlayClipAtPoint(keyGrab, transform.position);
  18.         
  19.         // ... the player has a key ...
  20.         playerInventory.hasKey = true;
  21.         
  22.         // ... and destroy this gameobject.
  23.         Destroy(gameObject);
  24.     }
  25. }
复制代码

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

GMT+8, 2024-11-23 18:55

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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