查看: 1059|回复: 0
打印 上一主题 下一主题

[提问] stealth代码问题求助

[复制链接]

1

主题

1

听众

357

积分

设计实习生

Rank: 2

纳金币
9
精华
0

最佳新人

跳转到指定楼层
楼主
发表于 2017-5-17 11:45:59 |只看该作者 |倒序浏览
这是stealth的代码,看红色字部分
using UnityEngine;
using System.Collections;

public class DonePlayerMovement : MonoBehaviour
{
        public AudioClip shoutingClip;                // Audio clip of the player shouting.
        public float turnSmoothing = 15f;        // A smoothing value for turning the player.
        public float speedDampTime = 0.1f;        // The damping for the speed parameter
       
       
        private Animator anim;                                // Reference to the animator component.
        private DoneHashIDs hash;                        // Reference to the HashIDs.

       
       
        void Awake ()
        {
                // Setting up the references.
                anim = GetComponent<Animator>();
                hash = GameObject.FindGameObjectWithTag(DoneTags.gameController).GetComponent<DoneHashIDs>();
               
                // Set the weight of the shouting layer to 1.
                anim.SetLayerWeight(1, 1f);
        }
       
       
        void FixedUpdate ()
        {
                // Cache the inputs.
                float h = Input.GetAxis("Horizontal");
                float v = Input.GetAxis("Vertical");
                bool sneak = Input.GetButton("Sneak");
               
                MovementManagement(h, v, sneak);
        }
       
       
        void Update ()
        {
                // Cache the attention attracting input.
                bool shout = Input.GetButtonDown("Attract");
               
                // Set the animator shouting parameter.
                anim.SetBool(hash.shoutingBool, shout);
               
                AudioManagement(shout);
        }
       
        这里的运动代码,是不是只有旋转没有移动,运行后角色只有旋转
        void MovementManagement (float horizontal, float vertical, bool sneaking)
        {
                // Set the sneaking parameter to the sneak input.
                anim.SetBool(hash.sneakingBool, sneaking);
               
                // If there is some axis input...
                if(horizontal != 0f || vertical != 0f)
                {
                        // ... set the players rotation and set the speed parameter to 5.5f.
                        Rotating(horizontal, vertical);
                        anim.SetFloat(hash.speedFloat, 5.5f, speedDampTime, Time.deltaTime);
                }
                else
                        // Otherwise set the speed parameter to 0.
                        anim.SetFloat(hash.speedFloat, 0);
        }
        高手指点一下
       
        void Rotating (float horizontal, float vertical)
        {
                // Create a new vector of the horizontal and vertical inputs.
                Vector3 targetDirection = new Vector3(horizontal, 0f, vertical);
               
                // Create a rotation based on this new vector assuming that up is the global y axis.
                Quaternion targetRotation = Quaternion.LookRotation(targetDirection, Vector3.up);
               
                // Create a rotation that is an increment closer to the target rotation from the player's rotation.
                Quaternion newRotation = Quaternion.Lerp(GetComponent<Rigidbody>().rotation, targetRotation, turnSmoothing * Time.deltaTime);
               
                // Change the players rotation to this new rotation.
                GetComponent<Rigidbody>().MoveRotation(newRotation);
        }
       
       
        void AudioManagement (bool shout)
        {
                // If the player is currently in the run state...
                if(anim.GetCurrentAnimatorStateInfo(0).nameHash == hash.locomotionState)
                {
                        // ... and if the footsteps are not playing...
                        if(!GetComponent<AudioSource>().isPlaying)
                                // ... play them.
                                GetComponent<AudioSource>().Play();
                }
                else
                        // Otherwise stop the footsteps.
                        GetComponent<AudioSource>().Stop();
               
                // If the shout input has been pressed...
                if(shout)
                        // ... play the shouting clip where we are.
                        AudioSource.PlayClipAtPoint(shoutingClip, transform.position);
        }
}


分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

关闭

站长推荐上一条 /1 下一条

手机版|纳金网 ( 闽ICP备08008928号

GMT+8, 2024-5-6 14:22 , Processed in 0.081257 second(s), 28 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部