Unity 2D地面陷阱和死亡特效

一,把陷阱制作成预制体;

二,把角色死亡特效制作成预制体

三,有一些公共变量要拖进脚本里

四,特效要及时的销毁,给特效预制体添加脚本DeadDestroy;

五,脚本

11,LevelManager 2 3using System.Collections; 4using System.Collections.Generic; 5using UnityEngine; 6 7public class LevelManager : MonoBehaviour { 8 9 public PlayerController thePlayer; 10 11 //角色死亡特效 12 public GameObject DeadExplosion; 13 14 void Start () { 15 16 //在游戏运行时,首先遍历一遍PlayerController脚本 17 PlayerController thePlayer = FindObjectOfType<PlayerController>(); 18 19 } 20 21 // Update is called once per frame 22 void Update () { 23 24 } 25 26 /// <summary> 27 /// 调用方法Respawn开启携程方法RespawnCo,完成等待复活事件 28 /// </summary> 29 public void Respawn() 30 { 31 //开启携程RespawnCo 32 StartCoroutine("RespawnCo"); 33 34 } 35 36 37 /// <summary> 38 /// 携程,等待X秒后复活角色 39 /// </summary> 40 /// <returns></returns> 41 public IEnumerator RespawnCo() 42 { 43 44 //隐藏角色 45 thePlayer.gameObject.SetActive(false); 46 //实例化一个角色死亡特效 47 Instantiate(DeadExplosion,thePlayer.transform.position,thePlayer.transform.rotation); 48 49 50 //等待X秒后执行 51 yield return new WaitForSeconds(3); 52 //把复活碰撞点的位置传给角色,让角色在复活碰撞点复活 53 54 thePlayer.transform.position = thePlayer.RespawnPosition; 55 //显示角色 56 57 thePlayer.gameObject.SetActive(true); 58 } 59 60} 61 622,HrutController 63 64using System.Collections; 65using System.Collections.Generic; 66using UnityEngine; 67 68public class HrutController : MonoBehaviour { 69 70 //要把LevelManager拖进脚本 71 public LevelManager theLevel; 72 73 void Start () { 74 75 theLevel = FindObjectOfType<LevelManager>(); 76 77 } 78 79 // Update is called once per frame 80 void Update () { 81 82 } 83 84 //角色碰到陷阱的时候调用Respawn复活角色 85 private void OnTriggerEnter2D(Collider2D collision) 86 { 87 if (collision.tag == "Player") 88 { 89 theLevel.Respawn(); 90 } 91 } 92} 93 943,DeadDestroy 95 96using System.Collections; 97using System.Collections.Generic; 98using UnityEngine; 99 100public class DeadDestroy : MonoBehaviour { 101 102 // Use this for initialization 103 void Start () { 104 Destroy(gameObject,1.5f); 105 } 106 107 // Update is called once per frame 108 void Update () { 109 110 } 111}
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

Twitter的分布式自增ID算法snowflake (Java版)

概述分布式系统中,有一些需要使用全局唯一ID的场景,这种时候为了防止ID冲突可以使用36位的UUID,但是UUID有一些缺点,首先他相对比较长,另外UUID一般是无序的。有些时候我们希望能使用一种简单一些的ID,并且希望ID能够按照时间有序生成。而twitter的snowflake解决了这种需求,最初Twitter把存储系统从MySQL迁移

Unity 2D地面陷阱和死亡特效 - HelloWorld