void Update() { //如果角色没有AI 直接返回 if (CurrRoleAI == null) { return; } CurrRoleAI.DoAI(); if (CurrRoleFSMMgr != null) { CurrRoleFSMMgr.OnUpdate(); } if (CharacterController == null) { return; } //让角色贴着地面 if (!CharacterController.isGrounded) { CharacterController.Move((transform.position + new Vector3(0, -1000, 0)) - transform.position); } if (CurrRoleType == RoleType.MainPlayer) { CameraAutoFollow(); } }
// Update is called once per frame void Update() { FSM.OnUpdate(); if (CurRoleAI == null) { return; } CurRoleAI.DoAI(); if (isInit) { isInit = false; if (CurRoleType == RoleType.Monster) { ToIdle(IdleType.IdleFight); } else { ToIdle(IdleType.IdleNormal); } } if (CurRoleType == RoleType.MainPlayer) { CameraAutoFollow(); } AutoSmallMap(); }
void Update() { if (CurrRoleFSMMgr != null) { CurrRoleFSMMgr.OnUpdate(); } //如果角色没有AI 直接返回 if (CurrRoleAI == null) { return; } CurrRoleAI.DoAI(); if (CharacterController == null) { return; } //让角色贴着地面 if (!CharacterController.isGrounded) { CharacterController.Move((transform.position + new Vector3(0, -1000, 0)) - transform.position); } if (Input.GetMouseButtonUp(1)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, Mathf.Infinity, 1 << LayerMask.NameToLayer("Item"))) { BoxCtrl boxCtrl = hit.collider.GetComponent <BoxCtrl>(); if (boxCtrl != null) { boxCtrl.Hit(); } } } //让角色贴着地面 if (!CharacterController.isGrounded) { CharacterController.Move((transform.position + new Vector3(0, -1000, 0)) - transform.position); } if (CurrRoleType == RoleType.MainPlayer) { CameraAutoFollow(); } AutoSamllMap(); }
void Update() { //如果当前角色没有AI,直接返回 if (CurrRoleAI == null) { return; } CurrRoleAI.DoAI(); if (CurrRoleFSMMgr != null) { CurrRoleFSMMgr.OnUpdate(); } if (CharacterController == null) { return; } //让角色贴着地面 if (!CharacterController.isGrounded) { CharacterController.Move((transform.position + new Vector3(0, -1000, 0)) - transform.position); } //if (Input.GetMouseButtonUp(1)) //{ // Collider[] colliderArr = Physics.OverlapSphere(transform.position, 3, 1 << LayerMask.NameToLayer("Item")); // if (colliderArr.Length > 0) // { // for (int i = 0; i < colliderArr.Length; i++) // { // Debug.Log("找到了附近的箱子" + colliderArr[i].gameObject.name); // } // } //} if (Input.GetMouseButtonUp(1)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); //RaycastHit[] hitArr = Physics.RaycastAll(ray, Mathf.Infinity, 1 << LayerMask.NameToLayer("Item")); //if (hitArr.Length > 0) //{ // for (int i = 0; i < hitArr.Length; i++) // { // Debug.Log("找到了" + hitArr[i].collider.gameObject.name); // } //} RaycastHit hit; if (Physics.Raycast(ray, out hit, Mathf.Infinity, 1 << LayerMask.NameToLayer("Item"))) { BoxCtrl boxCtrl = hit.collider.GetComponent <BoxCtrl>(); if (boxCtrl != null) { boxCtrl.Hit(); } } } //让角色贴着地面 if (!CharacterController.isGrounded) { CharacterController.Move((transform.position + new Vector3(0, -1000, 0)) - transform.position); } if (CurRoleType == RoleType.MainPlayer) { CameraAutoFollow(); } //if (Input.GetKeyUp(KeyCode.R)) //{ // ToRun(); //} //else if (Input.GetKeyUp(KeyCode.N)) //{ // ToIdle(); //} //else if (Input.GetKeyUp(KeyCode.A)) //{ // ToAttack(); //} //else if (Input.GetKeyUp(KeyCode.H)) //{ // ToHurt(); //} //else if (Input.GetKeyUp(KeyCode.D)) //{ // ToDie(); //} }
void Update() { //如果没有AI就不执行任何行为 if (RoleAI == null) { return; } //执行AI行为 RoleAI.DoAI(); Vector2 vec2 = Camera.main.WorldToScreenPoint(this.gameObject.transform.position); //判断角色是否再主相机内,如果不在就将其头顶UI隐藏,反之打开 if (IsInView(transform.position)) { if (m_HeadBar != null) { if (!m_HeadBar.activeSelf) { m_HeadBar.SetActive(true); } } } else { if (m_HeadBar != null) { if (m_HeadBar.activeSelf) { m_HeadBar.SetActive(false); } } } //每帧执行有限状态机的执行状态 if (RoleFSMMgr != null) { RoleFSMMgr.OnUpdate(); } if (CharacterCtrl == null) { return; } #region 主角移动 //如果角色没有着地,就迅速让其着地 if (!CharacterCtrl.isGrounded) { CharacterCtrl.Move(transform.position + new Vector3(0, -1000, 0) - transform.position); } #endregion //摄像机只跟随主角 if (CurrRoleType == RoleType.MainPlayer) { #region 摄像机的跟随和旋转 CameraAutoFllow(); #endregion } }