位置: 编程技术 - 正文
推荐整理分享unity学习之子弹发射(unity 子弹效果 粒子),希望有所帮助,仅作参考,欢迎阅读内容。
文章相关热门搜索词:unity怎么做子弹,unity子弹发射代码,unity子弹怎么从准星发出,unity怎么设置子弹发射方向,unity2d子弹,unity 子弹,unity 子弹,unity 子弹效果 粒子,内容如对您有帮助,希望把文章链接给更多的朋友!
欢迎来到unity学习教育专区,这里有丰富的unity资源,相信一定可以给你带来收获
今天我们根据昨天的知识讲了怎样发射子弹,并让子弹把墙打到
效果图如下:using UnityEngine;using System.Collections;public class fire : MonoBehaviour { float speed = 5.0f; public GameObject newObject; float firetima = 0.2f; float nexttime = 0.0f; // Use this for initialization void Start () { } // Update is called once per frame void Update () { float a = - * Time.deltaTime; float x = Input.GetAxis("Horizontal") * Time.deltaTime * speed; float z = Input.GetAxis("Vertical") * Time.deltaTime * speed; transform.Translate(x, 0, z); if (Input.GetKey(KeyCode.Z)) { transform.Rotate(Vector3.up * a, Space.Self); } if (Input.GetKey(KeyCode.X)) { transform.Rotate(Vector3.down * a, Space.Self); } if (Input.GetButton("Fire1") && nexttime < Time.time) { nexttime = firetima Time.time; GameObject go = Instantiate(newObject, transform.position, transform.rotation) as GameObject; go.rigidbody.AddForce(0, 0, ); } }}然后下午又讲了一个小游戏:飞机大战,不过才实现了其中的一小部分功能:点击鼠标左键或空键,我方飞机发射子弹效果图如下:代码如下:using UnityEngine;using System.Collections;public class Player : MonoBehaviour { float speed = -.0f; public GameObject Myplayer; void Update() { float a = Time.deltaTime; float x = Input.GetAxis("Horizontal") * Time.deltaTime * -speed; float z = Input.GetAxis("Vertical") * Time.deltaTime * -speed; transform.Translate(x, 0, z); if (Input.GetButton("Fire1") ) { //nexttime = firetima Time.time; GameObject go = Instantiate(Myplayer, transform.position, transform.rotation) as GameObject; go.rigidbody.AddForce(0, 0, ); Destroy(go,2.0f); } }}不要忘了吧子弹拖到预设体中,还要给子弹加上刚体,最重要是下图所指:更多精彩请点击
NGUI中Button的使用 Button控件主要分为两部分:Sprite(也就是背景)和Label(按钮上的文字);Button上的组件:Transform、BoxCollider、UIButton、UIButtonScale、UIButtonoffset、UIButtonSound
Unity学习之小结 欢迎大家来到我的博客
Unity组件添加与销毁 spanstyle=font-family:Arial,Helvetica,sans-serif;background-color:rgb(,,);1.程序中可以动态的给对象添加组件,添加方法/spanobj.AddComponent组件名/脚本名();如下prenam
标签: unity 子弹效果 粒子
本文链接地址:https://www.jiuchutong.com/biancheng/377297.html 转载请保留说明!友情链接: 武汉网站建设