static public Unit CreateUnit( Transform container, Board board, Vector2Int pos, UnitType type) { UnitBehaviour unitBehaviour = Object.Instantiate <UnitBehaviour> (type.Prefab, container); BaseAI ai = null; if (type.AI == UnitType.AIs.HERO) { ai = new HeroAI(); } else if (type.AI == UnitType.AIs.PATTERN) { ai = new PatternAI(type.PatternAIData); } else if (type.AI == UnitType.AIs.PROJECTILE) { ai = new ProjectileAI(); } Unit unit = new Unit(board, unitBehaviour, type, ai, pos); unitBehaviour.UpdateSprite(type.Image); unitBehaviour.UpdatePosition(pos); return(unit); }
//void HitTarget() //{ // target.GetComponent<PlayerHealth>().TakeDamage(damage); //} void FaceHero(HeroAI hero) { Vector3 direction = (hero.transform.position - transform.position).normalized; Quaternion lookRotation = Quaternion.LookRotation(new Vector3(direction.x, 0, direction.z)); transform.rotation = Quaternion.Slerp(transform.rotation, lookRotation, Time.deltaTime * turnSpeed); }
void OnTriggerExit(Collider other) { if ((other.GetComponent <Collider>().tag == "Heros") && enemyTarget != null) { enemyTarget = null; heroai = null; myState = EnemyState.Randommovemntget; } }
private IEnumerator Start() { yield return(new WaitForSeconds(heroSpawnDelay)); for (int i = 0; i < maxNumHeros; ++i) { HeroAI newHero = Instantiate(heros[Random.Range(0, heros.Length)], transform.position, Quaternion.identity); newHero.transform.parent = transform; } }
private void Awake() { myInfo = GetComponent<CharacterInfo>(); gameManager = GameObject.FindGameObjectWithTag("GameManager"); turnManager = gameManager.GetComponent<TurnManager>(); statusEffectManager = GetComponent<StatusEffectManager>(); gameInfo = gameManager.GetComponent<GameInfo>(); myAI = GetComponent<HeroAI>(); attackDelayTimer = gameObject.AddComponent<Timer>(); attackDelayTimer.Trigger += ExecuteHeroAction; attackShakeTimer = gameObject.AddComponent<Timer>(); attackShakeTimer.Trigger += ShakeMe; originalPosition = transform.position; }
private void Awake() { myInfo = GetComponent <CharacterInfo>(); gameManager = GameObject.FindGameObjectWithTag("GameManager"); turnManager = gameManager.GetComponent <TurnManager>(); statusEffectManager = GetComponent <StatusEffectManager>(); gameInfo = gameManager.GetComponent <GameInfo>(); myAI = GetComponent <HeroAI>(); attackDelayTimer = gameObject.AddComponent <Timer>(); attackDelayTimer.Trigger += ExecuteHeroAction; attackShakeTimer = gameObject.AddComponent <Timer>(); attackShakeTimer.Trigger += ShakeMe; originalPosition = transform.position; }
//public void OnHit() //{ // isProvoked = true; //} private void EngageHero(HeroAI hero) { if (distanceToTarget >= navMeshAgent.stoppingDistance) { MoveToHero(hero); } if (distanceToTarget <= navMeshAgent.stoppingDistance) { FaceHero(hero); AttackHero(hero); } }
void Start() { MyPickup = new PickupInfo(); MyDeliv = new DeliveryItem(); MaxWeight = 50; MyMoney = GameObject.FindGameObjectWithTag("PlayerTotals").GetComponent <MainMoney> (); MyHero = this.gameObject.GetComponent <HeroAI> (); // MainHandWeapon = new WeaponInfo (); // OffHandWeapon= new WeaponInfo (); // ShieldArmor= new ArmorInfo(); // ChestArmor = new ArmorInfo(); // HeadArmor= new ArmorInfo(); // LegArmor= new ArmorInfo(); // FeetArmor= new ArmorInfo(); }
void OnTriggerStay(Collider other) { if ((other.tag == "Heros") && enemyTarget == null) { Collider[] colliders = Physics.OverlapSphere(myTransform.position, sightRadius, 1 << 10); if (colliders.Length != 0) { GetComponent <Renderer>().enabled = true; // gameObject.GetComponent<EnemyHpDisplay>().GetComponent<Renderer>().enabled = true; gameObject.GetComponentInChildren <EnemyHpDisplay>().GetComponent <Renderer>().enabled = true; Collider nearestCollider = null; float minSqrDistance = Mathf.Infinity; for (int i = 0; i < colliders.Length; i++) { float sqrDistanceToCenter = (myTransform.position - colliders[i].transform.position).sqrMagnitude; if (sqrDistanceToCenter < minSqrDistance) { minSqrDistance = sqrDistanceToCenter; nearestCollider = colliders[i]; } } // Debug.Log (nearestCollider.tag+nearestCollider.name+this.name); enemyTarget = nearestCollider.gameObject; heroai = enemyTarget.GetComponent <HeroAI>(); myState = EnemyState.Attacking; movingTowards = enemyTarget.transform.position; } } if (other.tag == "Heros") { lastherosightingtimer = Time.time + 10; } }
void OnGUI() { int buttonW = 100, buttonH = 30, gapH = 35; int gapVal = 0; if (Hero == null) { if (GUI.Button(new Rect(0, 0, buttonW, buttonH), "connectLocal")) { NetMgr.getSingleton().connect(serverIPLocal, serverPort, OnConnectedSuccess); } if (GUI.Button(new Rect(0, gapVal += gapH, buttonW, buttonH), "connectRemote")) { NetMgr.getSingleton().connect(serverIPRemote, serverPort, OnConnectedSuccess); } regName = GUI.TextField(new Rect(buttonW, gapVal + gapH, buttonW, buttonH), regName); pwd = GUI.PasswordField(new Rect(buttonW * 2, gapVal + gapH, buttonW, buttonH), pwd, '*'); if (GUI.Button(new Rect(0, gapVal += gapH, buttonW, buttonH), "regist")) { JFPackage.PAG_REGIST regist = new JFPackage.PAG_REGIST(0, StringEncoding.GetBytes(regName), StringEncoding.GetBytes(pwd)); NetMgr.getSingleton().sendMsg(regist); } if (GUI.Button(new Rect(0, gapVal += gapH, buttonW, buttonH), "autoregist")) { JFPackage.PAG_REGIST regist = new JFPackage.PAG_REGIST(1, StringEncoding.GetBytes(regName), StringEncoding.GetBytes(pwd)); NetMgr.getSingleton().sendMsg(regist); } if (GUI.Button(new Rect(0, gapVal += gapH, buttonW, buttonH), "login")) { JFPackage.PAG_LOGIN login = new JFPackage.PAG_LOGIN(StringEncoding.GetBytes(regName), StringEncoding.GetBytes(pwd)); NetMgr.getSingleton().sendMsg(login); } if (GUI.Button(new Rect(0, gapVal += gapH, buttonW, buttonH), "enterMap")) { JFPackage.PAG_EnetrMap en = new JFPackage.PAG_EnetrMap(11); NetMgr.getSingleton().sendMsg(en); } } else { if (GUI.Button(new Rect(0, 0, buttonW, buttonH), "Again")) { HeroAI.reset(); } if (GUI.Button(new Rect(0, gapVal += gapH, buttonW, buttonH), "disconnected")) { //if(NetMgr.getSingleton().isConnected()) NetMgr.getSingleton().disConnect(); } if (GUI.Button(new Rect(0, gapVal += gapH, buttonW, buttonH), "relive")) { JFPackage.PAG_RELIVE re = new JFPackage.PAG_RELIVE(11); NetMgr.getSingleton().sendMsg(re); } // name,hp,mp,def Creature target = Hero.Target; selfInfo = Hero._name + ":" + Hero.shiled + ":" + Hero.hp + ":" + Hero.mp + ":" + "(" + Hero.ctl.curPos._x + ":" + Hero.ctl.curPos._z + ")"; selfInfoEx = Hero.maxHp + ":" + Hero.maxMp; if (target != null) { targetInfo = target._name + ":" + target.shiled + ":" + target.maxHp + ":" + target.hp + ":" + target.maxMp + ":" + target.mp + "(" + target.ctl.curPos._x + ":" + target.ctl.curPos._z + ")"; } GUI.Label(new Rect(0, gapVal += gapH, buttonW * 2, buttonH), selfInfo); GUI.Label(new Rect(0, gapVal += gapH, buttonW * 2, buttonH), selfInfoEx); GUI.Label(new Rect(0, gapVal += gapH, buttonW * 2, buttonH), targetInfo); } GUI.Label(new Rect(0, gapVal += gapH, buttonW * 3, buttonH * 2), GameDebug.lastError); }
public override void getCharacterAI() { this.characterAI = gameObject.GetComponent<HeroAI>(); this.heroAI = this.characterAI as HeroAI; }
public override void OnCreate() { base.OnCreate(); mAIMgr = new HeroAI(this); mLastPostion = transform.position; }
private void AttackHero(HeroAI hero) { GetComponent <Animator>().SetTrigger("TriggerAttack"); }
private void MoveToHero(HeroAI hero) { //GetComponent<Animator>().SetTrigger("TriggerMove"); navMeshAgent.SetDestination(hero.transform.position); }