我的游戏开发笔记(一):完善并把u3d自带的ThirdPersonController.js改成cs版本

刚开始学习u3d,u3d自带的ThirdPersonController.js实在是看得不太懂,而且动作实在太少了,想做一个动作类游戏都做不成。

今天初步把它改成了cs版本,并随便加了几个动作,以便后期使用。

每天奋斗一点点

.

using UnityEngine;
using System.Collections;

public class ThirdPersonControl : MonoBehaviour {

    #region 动作片段
    public AnimationClip idleAnimation;
    public AnimationClip walkAnimation;
    public AnimationClip runAnimation;
    public AnimationClip jumpPoseAnimation;
    public AnimationClip jumpFallAnimation;
    public AnimationClip kickAnimation;
    public AnimationClip utimateAnimation;
    private Animation _animation; 
    #endregion

    #region 动作片段枚举值
    enum CharacterState
    {
        Idle = 0,
        Walking = 1,
        Trotting = 2,
        Running = 3,
        Jumping = 4,
        Falling = 5,
        Kicking = 6,
        Utimate = 7
    } 
    #endregion

    #region 最大限速
    public float walkMaxAnimationSpeed = 0.75f;
    public float trotMaxAnimationSpeed = 1.0f;
    public float runMaxAnimationSpeed = 1.0f;
    public float jumpAnimationSpeed = 1.15f;
    public float landAnimationSpeed = 1.0f;
    public float kickMaxAnimationSpeed = 0.8f; 
    #endregion

    //判断游戏是否开始
    public static int jug = 0;
    
    //判断角色状态
    private CharacterState _characterState;

    #region 角色在做什么
    // Are we jumping? (Initiated with jump button and not grounded yet)
    //是否正在跳跃
    public bool jumping = false;
    private bool jumpingReachedApex = false;
    //是否正在踢人
    public bool kicking = false;
    //是否正在放大
    public bool utimating = false;
    //各种状态
    public bool slow = false;
    #endregion

    #region 记录动作开始时间以及各种参数
    // When did the user start walking (Used for going into trot after a while)
    //走路开始时间,一段时间后进入快跑状态
    private float walkTimeStart = 0.0f;
    // Last time the jump button was clicked down
    //最后一次按“跳跃按键的时间”
    private float lastJumpButtonTime = -10.0f;
    //跳
    private float lastJumpTime = -1.0f;
    //踢
    private float lastKickTime = -1.0f;
    //绝技
    private float lastUtimateTime = -0.1f;
    // the height we jumped from (Used to determine for how long to apply extra jump power after jumping.)
    //记录最后一次跳跃时的高度(高度过高会受伤之类的)
    private float lastJumpStartHeight = 0.0f;
    //绝技
    private float lastUtimateStartHeight = 0.0f;
    //落地
    private float lastGroundedTime = 0.0f;
    //跳跃参数
    private float jumpRepeatTime = 0.05f;
    private float jumpTimeout = 0.15f;
    private float groundedTimeout = 0.25f;
    //减速时间
    public float slowTime=0.0f;
    #endregion

    #region 角色基本属性,可以外部修改
    // The speed when walking
    public float walkSpeed = 2.0f;
    // after trotAfterSeconds of walking we trot with trotSpeed
    public float trotSpeed = 4.0f;
    // when pressing "Fire3" button (cmd) we start running
    public float runSpeed = 6.0f;
    public float kickSpeed = 3.0f;
    //????
    public float inAirControlAcceleration = 3.0f;
    // How high do we jump when pressing jump and letting go immediately
    public float jumpHeight = 0.5f;
    // The gravity for the character
    public float gravity = 20.0f;
    // The gravity in controlled descent mode
    public float speedSmoothing = 10.0f;
    public float rotateSpeed = 500.0f;
    public float trotAfterSeconds = 3.0f;
    //可跳与否
    public bool canJump = true;
    #endregion

    #region 各种私有变量
    // The camera doesnt start following the target immediately but waits for a split second to avoid too much waving around.
    private float lockCameraTimer = 0.0f;
    // The current move direction in x-z
    private Vector3 moveDirecti
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值