麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 編程設計 > 正文

Unity3D 沖鋒效果、角色拖尾效果

2020-07-14 13:22:46
字體:
來源:轉載
供稿:網友

《魔獸世界》,本人最喜歡的網絡游戲,如果你玩過戰士,你一定對戰士的沖鋒非常熟悉,現在接觸 Unity3D,因為最近用到了刀光、拖尾特效,所以就想做一個類似戰士的沖鋒效果,在本場景用到的拖尾效果可以查看我的另一篇文章,里面有詳細的介紹,刀光效果來自 Unity3D Assets 商店,只是把原作者的例子代碼整理了一下,變得非常簡單實用的類。

最終效果如下:

先來搭建我們的場景,如圖:

然后給角色的模型添加一個空對象,并且加上 MeshRender,并且設置好材質為 WeaponTrail,另外給這個空對象添加 WeaponTrail.cs 對象,設置好相關屬性,如圖:

下面的代碼是修改另一篇文章的 TrailsBladeMaster.cs 類,新的代碼如下:


復制代碼
代碼如下:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[AddComponentMenu("PocketRPG/Blade Master")]
public class TrailsBladeMaster : MonoBehaviour
{
/// <summary>
/// 拖尾效果
/// </summary>
public WeaponTrail weaponSwipe;
public AnimationClip idleClip;
public AnimationClip runClip;
/// <summary>
/// 移動速度
/// </summary>
public float speed = 20.0f;
public Camera mainCamera;
private Animation animation;
protected TrailsAnimationController animationController;
protected CharacterController characterController;
/// <summary>
/// 運行狀態
/// </summary>
private bool isMoving = false;
/// <summary>
/// 目標位置
/// </summary>
private Vector3 targetPosition;
/// <summary>
/// 移動向量
/// </summary>
private Vector3 moveDirection;
protected void Awake ()
{
this.animation = this.GetComponent<Animation> ();
this.animationController = this.GetComponent<TrailsAnimationController> ();
this.characterController = this.GetComponent<CharacterController> ();
this.animation.CrossFade (this.idleClip.name);
}
protected void Start ()
{
if (this.weaponSwipe != null) this.animationController.AddTrail (this.weaponSwipe);
}
protected void Update ()
{
if (!this.isMoving && Input.GetMouseButtonDown(0))
{
this.targetPosition = this.GetWorldPosition();
if(this.targetPosition != Vector3.zero)
{
this.isMoving = true;
this.moveDirection = (this.targetPosition - this.transform.position).normalized * this.speed;
this.transform.rotation = Quaternion.LookRotation(new Vector3(this.moveDirection.x, 0f, this.moveDirection.z));
this.animation.CrossFade(this.runClip.name);
if(this.weaponSwipe != null) this.weaponSwipe.StartTrail(1f, 0f);
}
}
if (this.isMoving)
{
if(!this.IsArrivePosition())
{
this.characterController.Move(this.moveDirection * Time.deltaTime);
}
else
{
this.animation.CrossFade(this.idleClip.name);
if(this.weaponSwipe != null) this.weaponSwipe.ClearTrail();
this.transform.position = this.targetPosition;
this.isMoving = false;
}
}
}
/// <summary>
/// 驗證是否到達目標地點
/// </summary>
/// <returns><c>true</c> if this instance is arrive position; otherwise, <c>false</c>.</returns>
private bool IsArrivePosition()
{
Vector3 currentDirection = (this.targetPosition - this.transform.position).normalized;
if (this.CalculateNormalized (currentDirection) == this.CalculateNormalized (this.moveDirection) * -1)
{
return true;
}
return false;
}
/// <summary>
/// 規范化比較向量
/// </summary>
/// <returns>The normalized.</returns>
/// <param name="direction">Direction.</param>
private Vector3 CalculateNormalized(Vector3 direction)
{
Vector3 value = Vector3.zero;
value.x = direction.x > 0 ? 1 : -1;
value.z = direction.z > 0 ? 1 : -1;
return value;
}
/// <summary>
/// 獲取世界位置
/// </summary>
/// <returns>The world position.</returns>
private Vector3 GetWorldPosition()
{
Ray ray = this.mainCamera.ScreenPointToRay(Input.mousePosition);
RaycastHit raycastHit;
if(Physics.Raycast(ray, out raycastHit))
{
if(raycastHit.collider.gameObject.name == "Terrain")
{
return raycastHit.point;
}
}
return Vector3.zero;
}
}

最后給角色對象掛載 TrailsAnimationController.cs 組件以及 TrailsBladeMaster.cs 組件,同時還需要添加一個角色控制器(CharacterController),因為我們用這個來驅動角色移動,如圖:

最后運行可以查看效果,點擊地形,角色向目標點移動,并帶有拖尾效果。

百度網盤下載地下:http://pan.baidu.com/s/1hqeiREO 密碼: t41j

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 国产精品久久久久久久久久久久久久久久 | 国产精品视频2021 | 黄色免费电影网址 | 午夜国产福利 | 99视频有精品 | 成人短视频在线观看 | 深夜激情视频 | japanese massage tube | 精品一区二区三区中文字幕老牛 | 91性高湖久久久久久久久网站 | av色在线观看 | 欧美a级在线免费观看 | 久久老司机精品视频 | 国产99免费 | 精品成人网 | 日本在线精品视频 | 精品国产一区二区三区久久久蜜月 | 精品国产91久久久久久久妲己 | 羞羞羞网站 | 欧美日韩亚洲国产 | 黄视频网站免费 | 日韩视频在线观看免费 | 精品国产91一区二区三区 | 欧美一级黄带 | 亚洲成人免费网站 | 欧美日韩一 | 欧美ab | 看免费5xxaaa毛片 | 亚洲影院在线 | 日本在线观看一区二区 | 国产一区二区三区四区精 | 欧美在线观看视频一区二区 | 99精品视频在线导航 | 久久久精品网站 | 精品成人av一区二区在线播放 | 国产精品视频免费在线观看 | 天天黄色片| 涩涩操 | 亚洲综合无码一区二区 | 免费看成人av | 精品成人网 |