Unity3D游戏开发之角色冲锋效果、角色拖尾效果.doc_第1页
Unity3D游戏开发之角色冲锋效果、角色拖尾效果.doc_第2页
Unity3D游戏开发之角色冲锋效果、角色拖尾效果.doc_第3页
Unity3D游戏开发之角色冲锋效果、角色拖尾效果.doc_第4页
Unity3D游戏开发之角色冲锋效果、角色拖尾效果.doc_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

魔兽世界,本人最喜欢的网络游戏,如果你玩过战士,你一定对战士的冲锋非常熟悉,现在接触 Unity3D,因为最近用到了刀光、拖尾特效,所以就想做一个类似战士的冲锋效果,在本场景用到的拖尾效果可以查看我的另一篇文章,里面有详细的介绍,刀光效果来自 Unity3D Assets 商店,只是把原作者的例子代码整理了一下,变得非常简单实用的类。最终效果如下:1149.jpg (119.17 KB, 下载次数: 0)下载附件 保存到相册 2015-1-11 19:36 上传先来搭建我们的场景,如图:291.jpg (139.88 KB, 下载次数: 0)下载附件 保存到相册 2015-1-11 19:36 上传 然后给角色的模型添加一个空对象,并且加上 MeshRender,并且设置好材质为 WeaponTrail,另外给这个空对象添加 WeaponTrail.cs 对象,设置好相关属性,如图:文章来自【狗刨学习网】1. using UnityEngine;2. using System.Collections;3. using System.Collections.Generic;4.5. AddComponentMenu(PocketRPG/Blade Master)6. public class TrailsBladeMaster : MonoBehaviour7. 8. / 9. / 拖尾效果10. / 11. public WeaponTrail weaponSwipe;12.13. public AnimationClip idleClip;14. public AnimationClip runClip;15.16. / 17. / 移动速度18. / 19. public float speed = 20.0f;20.21. public Camera mainCamera;22.23. private Animation animation;24.25. protected TrailsAnimationController animationController;26. protected CharacterController characterController;27.28. / 29. / 运行状态30. / 31. private bool isMoving = false;32.33. / 34. / 目标位置35. / 36. private Vector3 targetPosition;37.38. / 39. / 移动向量40. / 41. private Vector3 moveDirection;42.43. protected void Awake ()44. 45. this.animation = this.GetComponent ();46. this.animationController = this.GetComponenttr ();47. this.characterController = this.GetComponent ();48.49. this.animation.CrossFade (this.idleC);50. 51. protected void Start ()52. 53. if (this.weaponSwipe != null) this.animationController.AddTrail (this.weaponSwipe);54. 55.56. protected void Update ()57. 58. if (!this.isMoving & Input.GetMouseButtonDown(0) 59. 60. this.targetPosition = this.GetWorldPosition();61. if(this.targetPosition != Vector3.zero)62. 63. this.isMoving = true;64. this.moveDirection = (this.targetPosition - this.transform.position).normalized * this.speed;65. this.transform.rotation = Quaternion.LookRotation(new Vector3(this.moveDirection.x, 0f, this.moveDirection.z);66. this.animation.CrossFade(this.runC);67. if(this.weaponSwipe != null) this.weaponSwipe.StartTrail(1f, 0f); 68. 69. 70. if (this.isMoving) 71. 72. if(!this.IsArrivePosition()73. 74. this.characterController.Move(this.moveDirection * Time.deltaTime);75. 76. else77. 78. this.animation.CrossFade(this.idleC);79. if(this.weaponSwipe != null) this.weaponSwipe.ClearTrail();80. this.transform.position = this.targetPosition;81. this.isMoving = false;82. 83. 84. 85.86. / 87. / 验证是否到达目标地点88. / 89. / true if this instance is arrive position; otherwise, false.90. private bool IsArrivePosition()91. 92. Vector3 currentDirection = (this.targetPosition - this.transform.position).normalized;93. if (this.CalculateNormalized (currentDirection) = this.CalculateNormalized (this.moveDirection) * -1)94. 95. return true;96. 97. return false;98. 99.100. / 101. / 规范化比较向量102. / 103. / The normalized.104. / Direction.105. private Vector3 CalculateNormalized(Vector3 direction)106. 107. Vector3 value = Vector3.zero;108. value.x = direction.x 0 ? 1 : -1;109. value.z = direction.z 0 ? 1 : -1;110. return value;111. 112.113. / 114. / 获取世界位置115. / 116. / The world position.117. private Vector3 GetWorldPosition()118. 119. Ray ray = this.mainCamera.ScreenPointToRay(Input.mousePosition);120. RaycastHit raycastHit;121. if(Physics.Raycast(ray, out raycastHit)122. 123. if(raycastHit.collider.gameO = Terrain)124. 125. return raycastHit.point;126. 127. 128. return Vector3.zero;129. 130. 复制代码 最后给角色对象挂载 TrailsAnimationContro

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论