示例#1
0
    public override void _Process(float delta)
    {
        if (footStepTimer <= 0)
        {
            if ((Vector3)player.Get("direction") != Vector3.Zero && feet.IsColliding())
            {
                // Get collided body group name
                Godot.Collections.Array collidedGroups = ((Node)feet.GetCollider()).GetGroups();

                foreach (String group in collidedGroups)
                {
                    if (footStepList.ContainsKey(group))
                    {
                        Node footStepNode = footStepList[group];
                        if (footStepNode.GetChildCount() > 0)
                        {
                            // Play audio
                            int randomIndex           = (int)GD.RandRange(0, footStepNode.GetChildCount() - 1);
                            AudioStreamPlayer3D audio = (AudioStreamPlayer3D)footStepNode.GetChild(randomIndex);
                            audio.Play();

                            // Sync player speed with audio loop
                            footStepTimer = (1 - (0.06f * (float)player.Get("normalSpeed")));
                            break;
                        }
                    }
                }
            }
        }
        else
        {
            footStepTimer -= delta;
        }
    }