void setMYPlayer() { if (SCR_main.allPlayersGroup_A.Contains(this)) { groupType = GROUP_A; AllMyEnemys = SCR_main.allPlayersGroup_B; } else if (SCR_main.allPlayersGroup_B.Contains(this)) { groupType = GROUP_B; AllMyEnemys = SCR_main.allPlayersGroup_A; Debug.Log("GroupA players=" + AllMyEnemys.Count); } float distance = Mathf.Infinity; Vector3 position = transform.position; foreach (SCR_enemyAI myPlyr in AllMyEnemys) { if (myPlyr.groupType != groupType) { curDistance = Vector3.Distance(myPlyr.transform.position, transform.position); if (curDistance < distance) { currentTargetEnemy = myPlyr; distance = curDistance; } } } if (currentTargetEnemy == null) { //currentTargetEnemy = GameObject.FindWithTag ("Player").GetComponent<SCR_character> (); Debug.Log("no groups found.."); } else { Debug.Log("found closest.."); } }
void CreateEnemy(int enemySlot, Vector3 enemyPos) { SCR_enemyAI enemyInst = Instantiate(enemyObjects[enemySlot], enemyPos, Quaternion.identity) as SCR_enemyAI; if (enemyPos.x < 0) { SCR_main.allPlayersGroup_A.Add(enemyInst); } else { SCR_main.allPlayersGroup_B.Add(enemyInst); if (enemyInst.pointerObj) { enemyInst.pointerObj.SetActive(false); } } enemyInst.GetComponent <SCR_characterHealth>().StartUp(enemyTotal); enemyTotal++; enemyStock--; }
void Awake() { int i=0; //Mesh Setup int meshCount=0; for(i=0; i<2; i++){ foreach (Renderer m in gameObject.GetComponentsInChildren<Renderer>()){ if(i==1){ mesh[meshCount]=m; } meshCount++; } if(i==0){ mesh=new Renderer[meshCount]; } meshCount=0; } //Player or Enemy if(GetComponent<SCR_characterControl>()){ gameObject.tag="Player"; isPlayer=true; cc=GetComponent<SCR_characterControl>(); SetRotAngle(transform.position+(Vector3.forward*-10f)); SetRotTarget(); } else { gameObject.tag="Enemy"; isPlayer=false; invulnerable=true; ai=GetComponent<SCR_enemyAI>(); StartFlash(1,4); float patrolMult=0.5f; runSpeedArray=new float[2]{ runSpeed, runSpeed*patrolMult }; runAnimSpeedPatrol=(animSpeed[1]*patrolMult); } //Melee or Ranged if(GetComponent<SCR_characterMelee>()){ characterMelee=GetComponent<SCR_characterMelee>(); characterMelee.StartUp(isPlayer); melee=true; } else { characterRanged=GetComponent<SCR_characterRanged>(); melee=false; } //Animation Setup int animCount=0; for(i=0; i<2; i++){ foreach (AnimationState clip in GetComponent<Animation>()) { if(i==1){ animArray[animCount]=clip.name; } animCount++; } if(i==0){ animArray=new string[animCount]; animCount=0; } } //Set the cross fade speed for each animation animBlendSpeed=new float[9]{ 0.15f, 0.15f, 0.1f, 0.15f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; //Set the speed for each animation for(i=0; i<animArray.Length; i++){ if(GetComponent<Animation>()[animArray[i]]){ GetComponent<Animation>()[animArray[i]].speed=animSpeed[i]; } } if(rollSound){ SND_roll=SCR_main.CreateSound(transform,rollSound,false,true); } if(GetComponent<BoxCollider>()){ hitBoxSize=(GetComponent<BoxCollider>().size.x*transform.localScale.x*0.5f); } transform.rotation=rotTarget; if(isPlayer){ cc.StartUp(); } else { ai.StartUp(); } }
void setMYPlayer() { if(SCR_main.allPlayersGroup_A.Contains(this)){ groupType = GROUP_A; AllMyEnemys = SCR_main.allPlayersGroup_B; }else if(SCR_main.allPlayersGroup_B.Contains(this)){ groupType = GROUP_B; AllMyEnemys = SCR_main.allPlayersGroup_A; Debug.Log("GroupA players="+AllMyEnemys.Count); } float distance = Mathf.Infinity; Vector3 position = transform.position; foreach (SCR_enemyAI myPlyr in AllMyEnemys) { if(myPlyr.groupType != groupType){ curDistance = Vector3.Distance(myPlyr.transform.position , transform.position); if (curDistance < distance) { currentTargetEnemy = myPlyr; distance = curDistance; } } } if (currentTargetEnemy == null) { //currentTargetEnemy = GameObject.FindWithTag ("Player").GetComponent<SCR_character> (); Debug.Log("no groups found.."); } else { Debug.Log("found closest.."); } }
void Awake() { int i = 0; //Mesh Setup int meshCount = 0; for (i = 0; i < 2; i++) { foreach (Renderer m in gameObject.GetComponentsInChildren <Renderer>()) { if (i == 1) { mesh[meshCount] = m; } meshCount++; } if (i == 0) { mesh = new Renderer[meshCount]; } meshCount = 0; } //Player or Enemy if (GetComponent <SCR_characterControl>()) { gameObject.tag = "Player"; isPlayer = true; cc = GetComponent <SCR_characterControl>(); SetRotAngle(transform.position + (Vector3.forward * -10f)); SetRotTarget(); } else { gameObject.tag = "Enemy"; isPlayer = false; invulnerable = true; ai = GetComponent <SCR_enemyAI>(); StartFlash(1, 4); float patrolMult = 0.5f; runSpeedArray = new float[2] { runSpeed, runSpeed *patrolMult }; runAnimSpeedPatrol = (animSpeed[1] * patrolMult); } //Melee or Ranged if (GetComponent <SCR_characterMelee>()) { characterMelee = GetComponent <SCR_characterMelee>(); characterMelee.StartUp(isPlayer); melee = true; } else { characterRanged = GetComponent <SCR_characterRanged>(); melee = false; } //Animation Setup int animCount = 0; for (i = 0; i < 2; i++) { foreach (AnimationState clip in GetComponent <Animation>()) { if (i == 1) { animArray[animCount] = clip.name; } animCount++; } if (i == 0) { animArray = new string[animCount]; animCount = 0; } } //Set the cross fade speed for each animation animBlendSpeed = new float[9] { 0.15f, 0.15f, 0.1f, 0.15f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; //Set the speed for each animation for (i = 0; i < animArray.Length; i++) { if (GetComponent <Animation>()[animArray[i]]) { GetComponent <Animation>()[animArray[i]].speed = animSpeed[i]; } } if (rollSound) { SND_roll = SCR_main.CreateSound(transform, rollSound, false, true); } if (GetComponent <BoxCollider>()) { hitBoxSize = (GetComponent <BoxCollider>().size.x *transform.localScale.x *0.5f); } transform.rotation = rotTarget; if (isPlayer) { cc.StartUp(); } else { ai.StartUp(); } }