3d保龄球有没有背景是辽宁号航空母舰舰的

Unity3D开发类似保龄球游戏 - 推酷
Unity3D开发类似保龄球游戏
先学习一些基本的脚本实现:
1.动态创建物体.默认位置是(0,0)位置
GameObject goNew = GameObject.CreatePrimitive(PrimitiveType.Cube);
//创建的位置
goNew.transform.position = new Vector3(0, 0, -2);
&goNew.AddComponent&Rigidbody&();//添加刚体组件,是一种泛型
2.判断用户是否按下鼠标左键
if(Inut.GetMouseButtonDown(0))
3.按下鼠标左键,给它一个往前的脉冲力,forward就是一个默认长度为1的单位向量
this.gameObject.rigidbody.AddForce(Vector3.forward * 50, ForceMode.Impulse);
4.给当前物体添加一个往鼠标点击的方向的多大的力,它就会往那个方向去走
&//点击目标然后从摄像机的位置发射出一个小球,这里要计算力的方向向量
&Vector3 targetPos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 3));
Vector3 dir = targetPos - Camera.main.transform.
//给当前的物体添加某个方向的力
this.gameObject.rigidbody.AddForce(dir * 5,ForceMode.Impulse);
5.点击鼠标生成对象
if (Input.GetMouseButtonDown(0))
& & &GameObject goNew = GameObject.CreatePrimitive(PrimitiveType.Sphere);
& & &goNew.transform.position = new Vector3(0, 0, 0);
& & & goNew.AddComponent&Rigidbody&();
6.对象销毁回收内存
if (Input.GetMouseButtonDown(0))
& & & GameObject s1 = GameObject.Find(&Sphere&);//相当于document.getElementById();
& & & &Destroy(s1,2); //延时2秒销毁对象
制作游戏:
using UnityE
using System.C
public class gameText : MonoBehaviour {
& & private GameObject goP
// Use this for initialization
void Start () {
& & & & //找到地形对象
& & & & goPlane = GameObject.Find(&Plane&);
& & & & //创建4*4的cube
& & & & for (int i = 0; i & 4; i++)
& & & & & & for (int j = 0; j & 4; j++)
& & & & & & {
& & & & & & & & GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube);
& & & & & & & & go.transform.position = new Vector3(i, j, -1);
& & & & & & & & go.AddComponent&Rigidbody&();
& & & & & & & & go.AddComponent&AutoDistory&();//相当于实例化一个脚本销毁对象的一个类然后挂到每个对象中,让他不可见的时候自行销毁
& & & & & & }
// Update is called once per frame
void Update () {
& & & & if (Input.GetMouseButtonDown(0))
& & & & & & //创建子弹的object
& & & & & & GameObject goBullet = GameObject.CreatePrimitive(PrimitiveType.Sphere);
& & & & & & goBullet.transform.position = Camera.main.transform.
& & & & & & goBullet.AddComponent&Rigidbody&();
& & & & & & //让对象不可见的时候自行销毁
& & & & & & goBullet.AddComponent&AutoDistory&();
& & & & & &&
& & & & & & //获取到这个对象的多有资源,在发射的时候播放一个音乐
& & & & & & goPlane.GetComponent&AudioSource&().Play();
& & & & & & //点击鼠标,从摄像机的位置开始发射小球
& & & & & & Vector3 targetPos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 3));
& & & & & & goBullet.rigidbody.AddForce((targetPos - Camera.main.transform.position) * 20, ForceMode.Impulse);
& & & & & &&
& & void OnGUI()
& & & & & & string s = &作者:丁小未&;
& & & & & & GUIStyle bb = new GUIStyle();
& & & & & & bb.normal.background =//设置背景
& & & & & & bb.normal.textColor = new Color(1,0,0);//设置颜色
& & & & & & bb.fontSize = 40;
& & & & & & GUI.Label(new Rect(40, 10, 100, 50), s, bb);
AutoDistory脚本:
using UnityE
using System.C
//当东西不可见的时候就让他自动销毁
public class AutoDistory : MonoBehaviour {
// Use this for initialization
void Start () {
// Update is called once per frame
void Update () {
& & void OnBecameInvisible()
& & & & Destroy(this.gameObject);
其他提示:
1.天空盒的导入,提醒不要全部导入,不然文件会很大,应用是点击Edit-》Render Setting,然后导入天空盒
2.音频文件是在Camera上添加Component-&Audio-&Audio Sourse,他自动附带的Audio Listenner
详细项目源码:
已发表评论数()
已收藏到推刊!
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见
正文不准确
排版有问题
没有分页内容
视频无法显示
图片无法显示相关“保龄球”387 张图片
相关素材5060708090100每页显示红动创办于2005年,老品牌值得信赖
在线客服 :
客服热线 :咨询电话 周一至周日:8:30-22:30(12:00-13:00及法定假日除外)服务咨询周一至周日:8:30-22:30(12:00-13:00及法定假日除外)意见反馈您的意见是我们不断进步的动力!}

我要回帖

更多关于 中国有没有航空母舰 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信