예제 #1
0
        //被敌人攻击
        public override void UnderAttack(ICharactor theTarget)
        {
            var dir   = Vector3.Normalize(theTarget.transform.position - transform.position);
            var value = UsefulView(theTarget);

            //背面
            if (value >= 0 && value < 60)
            {
                //没有找到相应的动画,用正面被攻击的替代
                MyActionManager.General.GetDamageAnimation(0, 0);                 //触发被攻击动画
            }

            //侧面
            else if (value >= 60 && value < 120)
            {
                //右
                if (dir.x > 0)
                {
                    MyActionManager.General.GetDamageAnimation(-1, 0);                     //触发被攻击动画
                }
                //左
                else if (dir.x < 0)
                {
                    MyActionManager.General.GetDamageAnimation(1, 0);                     //触发被攻击动画
                }
            }

            //正面
            else if (value >= 120 && value <= 180)
            {
                MyActionManager.General.GetDamageAnimation(0, 0);                 //触发被攻击动画
            }

            //计算伤害值
            CharactorAttr.GetRemainHp(theTarget);
            if (CharactorAttr.GetNowHp() <= 0)
            {
                MyActionManager.General.GetDeadAnimation();                 //触发死亡动画
            }

//			Debug.Log("最大生命值" + CharactorAttr.GetMaxHp());
//			Debug.Log("当前生命值" + CharactorAttr.GetNowHp());
//			Debug.Log("当前伤害" + GetAtkValue());
        }
예제 #2
0
        private void Awake()
        {
            //初始化控制器,默认为手柄
            _controller = new JoyStrickInput();

            //初始化控制器状态,默认为手柄状态
            _controllerState = ControllerState.JoyStrick;

            //获取人物模型
            MyModel = this.transform.Find("ybot").gameObject;

            //获取角色控制柄下的刚体组件
            Rig = this.GetComponent <Rigidbody>();

            //获取角色控制柄下的碰撞体组件
            Col = this.transform.GetComponent <CapsuleCollider>();

            //获取传感器
            Sensor = this.transform.Find("Sensor").gameObject;

            //如果模型存在,则获取模型下的动画状态机
            if (MyModel)
            {
                MyAnimator = MyModel.GetComponent <Animator>();
            }

            //角色属性初始化
            SetCharactorAttr(new PlayerAttr());
            CharactorAttr.SetAttrStrategy(new PlayerAttrStrategy());
            CharactorAttr.InitAttr();

            //武器初始化
            SetWeapon(new WeaponSword());
            WeaponInit();

            //状态机动画管理
            InitActionManager();
            SetAnimation(new PlayerGeneralAnimationMgr(MyActionManager), new PlayerEqipAnimationMgr(MyActionManager),
                         new PlayerUnEqipAnimationMgr(MyActionManager));
        }