- 最后登录
- 2018-12-19
- 注册时间
- 2012-8-20
- 阅读权限
- 90
- 积分
- 54706
- 纳金币
- 32328
- 精华
- 41
|
开发环境Window7unity3d 3.4.1MB525defyAndroid 2.2.1虽然标题是游戏开发,其实也是羽化测试鼠标和弹幕的时候做的一个小游戏,于是一点点有模有样了,至于为什么又是方块,囧!所以就分享出来,内容很简陋,代码很简单,先送上效果截图。。。Android中PlanA是二刀流版- -大家凑合看吧-0- 本次学习:1. 弹幕追踪简单AI2. Unity鼠标特效 1. 弹幕追踪简单AI群里面有人共享的一个网页弹幕代码,通过XML控制,做得真的很不错,这里的弹幕AI很简单,可以用到很多飞行游戏中,如果想做出花哨的子弹轨迹效果,这个要花很多时间在上面钻研了,这里的代码只能实现前期的轨迹与方位追踪。希望能给大家参考~ ~Boss.js◦var target : Transform;
◦var speed : float = 4.0;
◦var LookAt : boolean = ***e;
◦var go : boolean = false;
◦private var mx : float;
◦private var my : float;
◦private var mz : float;
◦private var dis : float;
◦private var save : Vector3;
◦private var time : int;
◦
◦function Start()
◦{
◦ save = transform.position;
◦ dis = Random.value * 8- 4;
◦ mx = Random.value * 8 - 4;
◦ my = Random.value * 8 - 4;
◦ mz = Random.value * 8 - 4;
◦ time = 30 - Random.value*30;
◦ yield WaitForSeconds (time);
◦ go = ***e;
◦}
◦
◦function Update ()
◦{
◦ if(go)
◦ {
◦ if(Vector3.Distance(target.position, transform.position) > 5 && LookAt)
◦ {
◦ transform.LookAt(target.position);
◦ }
◦ else if(Vector3.Distance(target.position, transform.position) < 5)
◦ {
◦ LookAt = false;
◦ Destroy(gameObject,2);
◦ }
◦ transform.Translate(Vector3.forward * Time.deltaTime*speed);
◦ }
◦ else
◦ {
◦ transform.RotateAround(Vector3(mx,my,mz),save + Vector3(mx,my,0),Time.deltaTime * speed * dis);
◦ }
◦}
2. Unity鼠标特效 上篇提过鼠标特效的事情,于是羽化就做了测试,由于现在公司游戏主攻Web端,手机端在此之上删减,所以操作性质就发生了改变,但羽化还是写了手机端的代码,还是二刀流- -,图片从晚上找的,这里提供了两种鼠标特效,当然在真正做的时候羽化估计会用第二种加强版,所以看大家的平台和需求来。MOUSE.js◦var target1 : Transform;
◦var target1C : Transform;
◦var target2 : Transform;
◦var target2C : Transform;
◦var mousePos1 : Vector3;
◦var mousePos2 : Vector3;
◦var cursorImage : Texture;
◦var Mouse : GUISkin;
◦private var MouseImg : boolean = false;
◦
◦function Update()
◦{
◦ if(Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)
◦ {
◦ if(Input.touchCount == 1)
◦ {
◦ mousePos1 = Input.touches[0].position;
◦ }
◦ else if(Input.touchCount == 2)
◦ {
◦ mousePos1 = Input.touches[0].position;
◦ mousePos2 = Input.touches[1].position;
◦ }
◦ }
◦ else
◦ {
◦ mousePos1 = Input.mousePosition;
◦ }
◦ target1.position = camera.ScreenToWorldPoint (Vector3(mousePos1.x,mousePos1.y,1));
◦ target2.position = camera.ScreenToWorldPoint (Vector3(mousePos2.x,mousePos2.y,1));
◦}
◦
◦function LateUpdate()
◦{
◦ if(Input.GetKey(KeyCode.Escape))
◦ {
◦ Application.Quit();
◦ }
◦}
◦
◦function OnGUI()
◦{
◦ if(MouseImg)
◦ {
◦ GUI.skin = Mouse;
◦ var windowRect : Rect = Rect (mousePos1.x - cursorImage.width/2, Screen.height - mousePos1.y - cursorImage.height/2, cursorImage.width, cursorImage.height);
◦ windowRect = GUI.Window (0, windowRect, DoMyWindow, "My Window");
◦ }
◦
◦ if(GUILayout.Button("lanA"))
◦ {
◦ Screen.showCursor = !Screen.showCursor;
◦ target1.gameObject.active = !target1.gameObject.active;
◦ target1C.gameObject.active = target1.gameObject.active;
◦ if(Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)
◦ {
◦ target2.gameObject.active = !target2.gameObject.active;
◦ target2C.gameObject.active = target2.gameObject.active;
◦ }
◦ }
◦ else if(GUILayout.Button("lanB"))
◦ {
◦ Screen.showCursor = !Screen.showCursor;
◦ MouseImg = !MouseImg;
◦ }
◦ else if(GUILayout.Button("Restart"))
◦ {
◦ Application.LoadLevel(0);
◦ }
◦
◦ if(GUI.Button(new Rect(Screen.width-120,Screen.height-40,120,30),"Click to YUHUA!"))
◦ {
◦ Application.OpenURL("http://blog.csdn.net/libeifs");
◦ }
◦
◦ GUI.color = Color.white;
◦ GUILayout.Label("fps:" + FPS.fps.ToString("f0") + " " + FPS.afps.ToString("f0"));
◦}
◦
◦function DoMyWindow (windowID : int)
◦{
◦}
这里第二种替换图片,羽化用的是GUI中的Window,因为Window可以改变层级,大家研究下就知道,事件可以按需求自己判断。若大家有什么更好的点子,希望与羽化交流~ ~ 至于消除,碰撞什么的,羽化前面的博客里面都介绍过,大家可以参考下~ ~ 老样子工程送上:http://dl.dbank.com/c00te8j9aq
【来源:互联网】
更多精彩教程,尽在web3D纳金网http://www.narkii.com/college/ |
|