// Start is called before the first frame update void Start() { addRolePro(roleTransform.gameObject); roleProperty tmpPro = roleTransform.GetComponent <roleProperty>(); tmpPro.InitData(CamerTransform, CanvasTransform); tmpPro.showUI(); }
private void OnCollisionEnter(Collision collision) // void OnTriggerStay(Collider other) // private void OnTriggerEnter(Collider other) //需区分碰撞的对象,限制为敌人才有反应 { if (collision == null) { return; } // if (charInstance == null) // { // charInstance = App.Game.character; // } if ((selfAI == null) || (selfProperty == null)) { return; } ////以上为容错及过滤其它碰撞/////////// if (collision.collider.tag == csTagRole) //碰到角色 { roleProperty colPro = collision.gameObject.GetComponent <roleProperty>(); if ((colPro.roleSort != selfProperty.roleSort) && (colPro.hp > 0) && (selfProperty.hp > 0) ) //是敌人,且双方存活 { selfProperty.showUI(); //显示自己的UI即可 if (selfAI.enemyObj == null) //当前为空,马上攻击敌人 { selfAI.setEnemyObj(collision.gameObject); //设置朝向及攻击目标是相互的 selfAI.addEnemyToLst(collision.gameObject); selfAI.lookAtEnemy(selfAI.gameObject, selfAI.enemyObj); } else // { selfAI.addEnemyToLst(collision.gameObject); } } } /* * if (monControl.IsDie() == false) * { * * //判断目标是否存活 * //双方的enemy加上对方, 双方显示血条 * * if (monControl.IsInAttackState() == false) * { * monControl.setToAttack(charInstance.roleInstance.transform.position); * } * * }*/ }
public void setMonsterToAttack(Vector3 rolePos) { mMonsterPro.showUI(); //自身的UI显示 App.Game.character.setRoleAttack(this.gameObject); //showRoleUI(); Vector3 lookPos = new Vector3(rolePos.x, this.transform.position.y, rolePos.z); this.transform.LookAt(rolePos); animator.SetBool(csInAttack, true); }
// Update is called once per frame private void OnCollisionEnter(Collision collision) { if (collision == null) { return; } if ((selfAI == null) || (selfProperty == null)) { return; } if (collision.collider.tag == csTagRole) //碰到角色 { roleProperty colPro = collision.gameObject.GetComponent <roleProperty>(); if ((colPro.roleSort != selfProperty.roleSort) && (colPro.hp > 0) && (selfProperty.hp > 0) ) //是敌人,且双方存活 { selfProperty.showUI(); if (selfAI.enemyObj == null) { //进入战斗 CsdUIControlMgr.uiMgr().msgNoteTop(); selfAI.setEnemyObj(collision.gameObject); selfAI.addEnemyToLst(collision.gameObject); // selfAI.lookAtEnemy(selfAI.gameObject, selfAI.enemyObj); } else { selfAI.addEnemyToLst(collision.gameObject); } } } else if (collision.collider.tag == csTagGold) { // Debug.LogWarning("colision gold"); collision.transform.gameObject.SetActive(false); stageMgr.stage().addReward(); } }
//设置玩家为攻击状态 public void setRoleAttack(GameObject monsterObj) { //玩家UI显示 //roleProperty mainPro = roleInstance.transform.GetComponent<roleProperty>(); mainPro.showUI(); attackMonster = monsterObj; Vector3 rolePos = attackMonster.transform.position; if (roleIsEscape == false) //玩家不在逃跑中 { //玩家朝向怪物 Vector3 lookPos = new Vector3(rolePos.x, roleInstance.transform.position.y, rolePos.z); roleInstance.transform.LookAt(rolePos); //玩家切换攻击状态 mainRoleState.updataRoleControl(0, 0, true, false); roleIsAttack = true; } }
private void showRoleUI() { roleProperty mainPro = App.Game.character.roleInstance.transform.GetComponent <roleProperty>(); mainPro.showUI(); }