Javascript 我所做的航路点工作平稳,但改变速度值不会影响任何事情。为什么?

Javascript 我所做的航路点工作平稳,但改变速度值不会影响任何事情。为什么?,javascript,unity3d,unityscript,unity5,Javascript,Unity3d,Unityscript,Unity5,我现在面临的唯一问题是,在Inspector中,当更改巡逻速度值时,它不会影响角色行走的所有速度 我在window>Animator中创建了角色行走,在那里我创建了一个新的空状态,称为walk,并将运动设置为HumanoidWalk,然后将行走状态设置为Layer Default State 所以现在我的角色一直在行走,我用脚本告诉他在两个航路点之间行走 问题是如何改变行走速度 #pragma strict // The list of Waypoint you want the enemy

我现在面临的唯一问题是,在Inspector中,当更改巡逻速度值时,它不会影响角色行走的所有速度

我在window>Animator中创建了角色行走,在那里我创建了一个新的空状态,称为walk,并将运动设置为HumanoidWalk,然后将行走状态设置为Layer Default State

所以现在我的角色一直在行走,我用脚本告诉他在两个航路点之间行走

问题是如何改变行走速度

#pragma strict

// The list of Waypoint you want the enemy to traverse
public var waypoint : Transform[];  

// The walking speed between Waypoints    
public var patrolSpeed : float = 6;  

// Do you want to keep repeating the Waypoints    
public var loop : boolean = true;      

// How slowly to turn
public var dampingLook = 4;

// How long to pause at a Waypoint= 0;          
public var pauseDuration : float;

private var curTime : float;
private var currentWaypoint : int = 0;
public var character : CharacterController;

function Start(){

    //character = GetComponent(CharacterController);
}

function LateUpdate(){

    if(currentWaypoint < waypoint.length){
       patrol();
       }else{    
    if(loop){
       currentWaypoint=0;
        }
    }
}

function patrol(){

    var nextWayPoint : Vector3 = waypoint[currentWaypoint].position;

    // Keep waypoint at character's height
    nextWayPoint.y = transform.position.y;

    // Get the direction we need to move to
    // reach the next waypoint
    var moveDirection : Vector3 = nextWayPoint - transform.position;


    if(moveDirection.magnitude < 1.5){
        Debug.Log("enemy is close to nextwaypoint");


    // This section of code is called only whenever the enemy
    // is very close to the new waypoint
    // so it is called once after 4-5 seconds.

       if (curTime == 0)
           // Pause over the Waypoint
           curTime = Time.time;

           if ((Time.time - curTime) >= pauseDuration){
               Debug.Log("increasing waypoint");

                currentWaypoint++;
                curTime = 0;
           }
    }
    else
    {    
    Debug.Log("reaching in rotation " + moveDirection.magnitude);
       // This code gets called every time update is called
       // while the enemy if moving from point 1 to point 2.
       // so it gets called 100's of times in a few seconds  

       // Now we need to do two things
       // 1) Start rotating in the desired direction
       // 2) Start moving in the desired direction

       // 1) Let' calculate rotation need to look at waypoint
       // by simply comparing the desired waypoint & current transform
       var rotation = Quaternion.LookRotation(nextWayPoint - transform.position);

       // A slerp function allow us to slowly start rotating
       // towards our next waypoint
       transform.rotation = Quaternion.Slerp(transform.rotation, rotation,
                Time.deltaTime * dampingLook);

       // 2) Now also let's start moving towards our waypoint
       character.Move(moveDirection.normalized * patrolSpeed * Time.deltaTime);
    }  
}
#pragma strict
//您希望敌人通过的航路点列表
公共var航路点:转换[];
//航路点之间的行走速度
公共速度:浮动=6;
//你想继续重复航路点吗
公共变量循环:布尔值=true;
//转弯有多慢
公共var-dampingLook=4;
//在一个航路点停留的时间=0;
公共教育:浮动;
私有var-curTime:float;
专用var currentWaypoint:int=0;
公共变量字符:CharacterController;
函数Start(){
//character=GetComponent(CharacterController);
}
函数LateUpdate(){
if(当前航路点<航路点长度){
巡逻();
}否则{
如果(循环){
currentWaypoint=0;
}
}
}
功能巡逻(){
var nextWayPoint:Vector3=航路点[currentWaypoint]。位置;
//将航路点保持在角色高度
nextWayPoint.y=transform.position.y;
//找到我们要去的方向
//到达下一个航路点
var moveDirection:Vector3=nextWayPoint-transform.position;
如果(移动方向.幅值<1.5){
Log(“敌人接近下一个点”);
//这段代码只有在敌人
//非常接近新的航路点
//所以它在4-5秒后被调用一次。
如果(curTime==0)
//停在航路点上
curTime=Time.Time;
如果((Time.Time-curTime)>=暂停){
Debug.Log(“增加航路点”);
currentWaypoint++;
curTime=0;
}
}
其他的
{    
Debug.Log(“旋转到达”+moveDirection.MARGENT);
//每次调用update时都会调用此代码
//当敌人从1点移动到2点时。
//所以它在几秒钟内被调用了100次
//现在我们需要做两件事
//1)开始按所需方向旋转
//2)开始向所需方向移动
//1)让我们计算旋转,需要查看航路点
//通过简单比较所需的航路点和当前变换
var rotation=四元数.LookRotation(nextWayPoint-transform.position);
//slerp功能允许我们慢慢开始旋转
//朝着我们的下一个航路点
transform.rotation=Quaternion.Slerp(transform.rotation,rotation,
Time.deltaTime*dampingLook);
//2)现在让我们开始向我们的航路点移动
character.Move(moveDirection.normalized*巡逻速度*时间.deltaTime);
}  
}

如果它是一个公共变量,它可能不会在编辑器中表示为您在脚本中所做的更改,请尝试在编辑器中设置巡检速度。

我尝试更改行:public var patrolSpeed:float=6;对公速度:浮点数=20;但速度不变。我使用了一个断点,它不会到达直线:character.Move(moveDirection.normalized*patrolSpeed*Time.deltaTime);但是速度永远不会改变。一旦我改变了动画师的行走速度,它就开始工作了。添加了新的Animator变量,在更新函数中,我将Animation variable speed属性设置为速度。现在它开始工作了。