【跟我一起学Unity3D】做一个2D的90坦克大战之各种各样的墙<<附上项目源码>>

来源:互联网 发布:win10m vpn软件 编辑:程序博客网 时间:2024/05/02 06:46

最后一个就是各种各样的墙了,这个就相当简单了,设定一个属性作为墙的种类,然后根据不同的种类设置不同的墙的碰撞方式即可,当前有些墙之间在编辑器里面设置就可以了,脚本里面需要分辩的就是普通的墙和刚墙两种。

using UnityEngine;using System.Collections;public class CWalk : MonoBehaviour {    /// <summary>    /// 墙的类型 0 是普通墙 1是刚墙 2是草丛 3是水    /// </summary>    public int m_iTypeOfWall;    void Start()    {    }void Update () {}    void OnTriggerEnter2D(Collider2D other)    {        Debug.Log("OnTriggerEnter : " + other.gameObject.name);        //撞墙        if (other.gameObject.name == "MyTankBullet")        {            if (m_iTypeOfWall == 0 || m_iTypeOfWall == 1) Destroy(other.gameObject);            if (m_iTypeOfWall == 0) Destroy(this.gameObject);        }        if (other.gameObject.name == "AIBullet")        {            if (m_iTypeOfWall == 0 || m_iTypeOfWall == 1) Destroy(other.gameObject);            if (m_iTypeOfWall == 0) Destroy(this.gameObject);        }    }}

其实我的子弹和AI的 子弹的处理方式是一样的,写两个只是为了以后针对性的时候比较方便改。

最后是项目的源码:http://download.csdn.net/detail/baijiajie2012/8106425

0 0
原创粉丝点击