void Update() { if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hitinfo; // LayerMask mask = 1 << LayerMask.NameToLayer("GroundLayer"); bool isCollider = Physics.Raycast(ray, out hitinfo); if (isCollider && hitinfo.collider.tag == Tags.player) { cur_Role = hitinfo.collider.transform.parent.GetComponent<DBaseFightRole>(); } if (isCollider && hitinfo.collider.tag == Tags.ground && cur_Role != null) { NavMeshPath path = new NavMeshPath(); cur_Role.agent.enabled = true; cur_Role.agent.CalculatePath(hitinfo.point, path); if (path.corners.Length >= 2) { cur_Role.gotoDestination(hitinfo.point); } cur_Role = null; } } }
// Use this for initialization void Start () { targetPosition = transform.position; playermvoe = this.GetComponent<PlayerMove> (); agent = this.GetComponent<NavMeshAgent>(); playerattack = this.transform.parent.GetComponent<DBaseFightRole>(); }
// private NavMeshAgent agent; // Use this for initialization void Start () { dir = this.GetComponent<PlayerDir> (); controller = this.GetComponent<CharacterController> (); attack = this.transform.parent.GetComponent<DBaseFightRole>(); // agent = this.GetComponent<NavMeshAgent>(); }
public void setplayer(DBaseFightRole playrole) { player = playrole.roleModel.transform; transform.LookAt(player.position); offsetposition = transform.position - player.position; playrole.roleModel.AddComponent<PlayerMove>(); playrole.roleModel.AddComponent<PlayerDir>(); }
public void SetTargetPos(GameObject targetRole, SkillCasterData skilldata) { skillcastdata = skilldata; tragetfightrole = targetRole.GetComponent<DBaseFightRole>(); if (tragetfightrole != null) startFollow = true; //DBaseFightRole role = targetRole.GetComponent<DBaseFightRole>(); // iTween.MoveTo(gameObject, iTween.Hash("position", role.roleModel.transform.position + Vector3.up, "easeType", "easeInOutExpo", "time",0.7f,"delay", .1, "oncomplete", "showHitMovie")); }
public void setBuffData(DBuffData buffdata,DBaseFightRole effectrole) { data = buffdata; effRole = effectrole; string asseturl = UrlManager.GetEffectUrl(buffdata.effurl,EEffectType.Buff); GameObject prefab = ResourceManager.loadAsset<GameObject>(asseturl); if (prefab != null) { effectInstance = Instantiate(prefab, Vector3.zero, Quaternion.identity) as GameObject; effectInstance.transform.parent = transform; effectInstance.transform.localPosition = Vector3.zero; if (buffdata.bufftype == EBuffType.Temperary) Invoke("destroyEff", 5); else Invoke("destroyEff", buffdata.duration); } }
//寻找技能攻击对象 priority 优先攻击对象策略,isAttackEnemy 是攻击敌人,还是攻击己方,比如一些 加血,加防的技能攻击对象是己方,再比如混乱状态下 会攻击己方 public GameObject findAttackEnemy(DBaseFightRole attacker, EAttackStragety priority = EAttackStragety.EAttackStragety_Nearest,bool isAttackEnemy = true) { if(attacker != null) { int attackside = attacker.side; List<DBaseFightRole> tempEnemy = new List<DBaseFightRole>(); foreach(DBaseFightRole fightrole in allRoles) { if (isAttackEnemy && fightrole.side != attackside) { tempEnemy.Add(fightrole); } else if (!isAttackEnemy && fightrole.side == attackside && fightrole != attacker) tempEnemy.Add(fightrole); } return getEnemy(attacker, tempEnemy, priority); } return null; }
// Update is called once per frame void Update () { if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hitinfo; // LayerMask mask = 1 << LayerMask.NameToLayer("GroundLayer"); bool isCollider = Physics.Raycast(ray, out hitinfo); if (isCollider) { if (hitinfo.collider.transform.parent.GetComponent<DBaseFightRole>() != null) { cur_role = hitinfo.collider.transform.parent.GetComponent<DBaseFightRole>(); pname.text = cur_role.name; roleskill = hitinfo.collider.transform.parent.GetComponent<FightRoleSkill>(); }; } } }
public Vector3 getAttackPointByDist(DBaseFightRole attacker, DBaseFightRole target,float dist) { Vector3 vecToAttacker = attacker.rolePosition -target.rolePosition; Vector3 normalDirect = vecToAttacker.normalized * dist; Vector3 tempDirect; bool isOccupied = false; for (int i = 0; i < 6; i++) { tempDirect = target.rolePosition + Quaternion.Euler(0, 30 * i, 0)*normalDirect; isOccupied = false; foreach (DBaseFightRole other in allRoles) { if (other != attacker && other != target) { float tempdist = Vector3.Distance(other.rolePosition, tempDirect); if (tempdist < 3*(attacker.roleRadius + other.roleRadius)) { isOccupied = true; break; } } } if (!isOccupied && attacker.agent.enabled) { NavMeshPath path = new NavMeshPath(); attacker.agent.CalculatePath(tempDirect, path); if (path.corners.Length >= 2) { return tempDirect; } } tempDirect = target.rolePosition + Quaternion.Euler(0, -30 * i, 0) * normalDirect; isOccupied = false; foreach (DBaseFightRole other in allRoles) { if (other != attacker && other != target) { float tempdist = Vector3.Distance(other.rolePosition, tempDirect); if (tempdist < 3 * (attacker.roleRadius + other.roleRadius)) { isOccupied = true; break; } } } if (!isOccupied && attacker.agent.enabled) { NavMeshPath path = new NavMeshPath(); attacker.agent.CalculatePath(tempDirect, path); if (path.corners.Length >= 2) { return tempDirect; } } } return target.rolePosition; }
public bool isCollisionOther(DBaseFightRole role) { float size1 = role.agent.radius; float dist; bool iscollision = false; foreach (DBaseFightRole other in allRoles) { if (role != other) { dist = Vector3.Distance(role.rolePosition, other.rolePosition); Vector3 nextpos = role.rolePosition + (role.agent.destination - role.rolePosition).normalized * 0.1f; float nextdist = Vector3.Distance(nextpos, other.rolePosition); if (dist <= 2*size1 + other.agent.radius) { // iscollision = true; float destdit = Vector3.Distance(role.agent.destination, other.rolePosition); if (destdit < size1 + other.agent.radius + 0.2) iscollision = true; } } } return iscollision; }
public void roleDead(DBaseFightRole fightrole) { if (allRoles.Contains(fightrole)) allRoles.Remove(fightrole); }
public float getFightRoleDistance(DBaseFightRole role1, DBaseFightRole role2) { return Vector3.Distance(role1.rolePosition, role2.rolePosition); }
public GameObject getEnemy(DBaseFightRole attacker,List<DBaseFightRole> enemyList,EAttackStragety priority = EAttackStragety.EAttackStragety_Nearest) { GameObject resultEnemy = null; switch(priority) { case EAttackStragety.EAttackStragety_Nearest: float distance = 100; foreach(DBaseFightRole enemy in enemyList) { float tempdist = Vector3.Distance(attacker.rolePosition, enemy.rolePosition); if(tempdist < distance) { resultEnemy = enemy.gameObject; distance = tempdist; } } break; case EAttackStragety.EAttackStragety_MainRole: foreach (DBaseFightRole enemy in enemyList) { if(enemy.isMainRole) { resultEnemy = enemy.gameObject; break; } } break; } return resultEnemy; }
// Use this for initialization void Start () { fightrole = gameObject.GetComponent<DBaseFightRole>(); }
void Awake() { fightrole = gameObject.GetComponent<DBaseFightRole>(); }
public void TakeDamage(DBaseFightRole attackrole,SkillInfo skill) { }
public void setFollowTarget(DBaseFightRole target) { followTarget = target; }