コード例 #1
0
ファイル: HeroControllerScript.cs プロジェクト: Vasj0001/Game
	void DamageAI(){
		foreach(Transform x in targetsInRange){
				AIscript = (AI)x.GetComponent("AI");
				AIscript.AddJustCurrHealth(-DamageWW);
		}
	}
コード例 #2
0
ファイル: HeroControllerScript.cs プロジェクト: Vasj0001/Game
    private void Update()
    {	
		targetsInRange = targets.FindAll(bot =>((isFacingRight && Mathf.Abs(myPlayer.position.y-bot.position.y)<=1.2f && myPlayer.transform.position.x<=bot.transform.position.x && bot.transform.position.x<=myPlayer.transform.position.x+2.0f) || (!isFacingRight && myPlayer.transform.position.x-2.0f<=bot.transform.position.x && bot.transform.position.x<=myPlayer.transform.position.x)));
		//Debug.Log(_damageW);
		if (Input.GetKey(KeyCode.F))
			CurXP+=10;
		TargetEnemy();
		if (CurHealth>MaxHealth)
			CurHealth=MaxHealth;
		if (CurMana>MaxMana)
			CurMana=MaxMana;
		if (attackTimer>0){attackTimer-=Time.deltaTime;}
		if (attackTimer<0){attackTimer=0;}
		if (menuTimer>0){menuTimer-=Time.deltaTime;}
		if (menuTimer<0){menuTimer=0;}
		if (menuTimer==0 && menuCheck){
			NGUITools.SetActive (statsMenu, false);
			checkAudio=false;
		}
			
		if (firstSkillTimer>1){
			firstSkillTimer-=Time.deltaTime;
			cdFirstSkillText.text=(Mathf.Floor(firstSkillTimer)).ToString();
		}
		if (firstSkillTimer<1){
			firstSkillTimer=1;
			NGUITools.SetActive(fonFirstSkill,false);
		}
		//
		if (SecondSkillTimer>1){
			SecondSkillTimer-=Time.deltaTime;
			//cdSecondSkillText.text=(Mathf.Floor(SecondSkillTimer)).ToString();
		}
		if (SecondSkillTimer<1){
			SecondSkillTimer=1;
			//NGUITools.SetActive(fonSecondSkill,false);
		}
	
		if (NGUITools.GetActive(openMenu)){
			Time.timeScale=0;
		}
		else{
			Time.timeScale=1;
		}
	
	
        //если персонаж на земле и нажат пробел...
        if (!isSky && Input.GetKey(KeyCode.W) && !anim.GetCurrentAnimatorStateInfo(0).IsName("Attack_War")) 
        {
            //устанавливаем в аниматоре переменную в false
            //anim.SetBool("Ground", false);
            //прикладываем силу вверх, чтобы персонаж подпрыгнул
			myPlayer.position += myPlayer.up * maxSpeed * Time.deltaTime;
			//Debug.Log(maxSpeed);
        }
		if (!isGrounded && Input.GetKey(KeyCode.S) && !anim.GetCurrentAnimatorStateInfo(0).IsName("Attack_War")) 
        {
            //устанавливаем в аниматоре переменную в false
            //anim.SetBool("Ground", false);
            //прикладываем силу вверх, чтобы персонаж подпрыгнул
            myPlayer.position -= myPlayer.up * maxSpeed * Time.deltaTime;				
        }
		if (!block && Input.GetKeyDown(KeyCode.Mouse0)){
			//mouseOver = Input.mousePosition;
			//Debug.Log(mouseOver);
			//if (mouseOver.x >= 880.0f && !isFacingRight && !anim.GetCurrentAnimatorStateInfo(0).IsName("Attack_War")){Flip();}
			//if (mouseOver.x < 880.0f && isFacingRight && !anim.GetCurrentAnimatorStateInfo(0).IsName("Attack_War")){Flip();}
			if (attackTimer==0){
				anim.SetTrigger(attackHash);
				DamageAI();
				attackTimer=cd;
			}
		}
		//First Skill
		if (Input.GetKeyDown(KeyCode.Alpha1) && firstSkillTimer==1){
			firstSkillTimer=cdFirstSkill;
			NGUITools.SetActive(fonFirstSkill,true);
			wave.SetActive(true);
			ttlFirstSkill=1.0f;
			if(!isFacingRightFirstSkill){
				Vector3 theScale = wave.transform.localScale;
				theScale.x *= -1;
				wave.transform.localScale = theScale;
			}
			isFacingRightFirstSkill=isFacingRight;
			if(isFacingRightFirstSkill){
				wave.transform.position=new Vector3(myPlayer.position.x+1,myPlayer.position.y,0);
				rightPartSys.SetActive(true);
				leftPartSys.SetActive(false);
			}else{
				rightPartSys.SetActive(false);
				leftPartSys.SetActive(true);
				Vector3 theScale = wave.transform.localScale;
				theScale.x *= -1;
				wave.transform.localScale = theScale;
				isFacingRightFirstSkill=false;
				wave.transform.position=new Vector3(myPlayer.position.x-1,myPlayer.position.y,0);
			}
		}
		if (ttlFirstSkill>=0){
			if(isFacingRightFirstSkill){
				wave.transform.position += wave.transform.right * 7 * Time.deltaTime;
			}else{
				wave.transform.position -= wave.transform.right * 7 * Time.deltaTime;
			}
			targetsInFirstSkill= targets.FindAll(bot => Mathf.Abs(bot.position.x-wave.transform.position.x)<=1.0f && Mathf.Abs(bot.position.y-wave.transform.position.y)<=0.6f);
			foreach(Transform x in targetsInFirstSkill){
				if(!targetsDamagedFirstSkill.Contains(x)){
					AIscript = (AI)x.GetComponent("AI");
					AIscript.AddJustCurrHealth(-15);
					targetsDamagedFirstSkill.Add(x);
				}
			}
			ttlFirstSkill-=Time.deltaTime;
		}
		if (ttlFirstSkill<=0){
			wave.SetActive(false);
			targetsDamagedFirstSkill.Clear();
		}
		//
		//Second Skill
		if (Input.GetKeyDown(KeyCode.Alpha2) && SecondSkillTimer==1)
		{
			SecondSkillTimer=cdSecondSkill;
			//NGUITools.SetActive(fonSecondSkill,true);
			ttlSecondSkill=0.2f;
			isFacingRightSecondSkill=isFacingRight;
		}
		if (ttlSecondSkill>=0)
		{
			if(isFacingRightSecondSkill)
			{
				myPlayer.transform.position += myPlayer.transform.right * maxSpeed * 8 * Time.deltaTime;
			}
			else
			{
				myPlayer.transform.position -= myPlayer.transform.right * maxSpeed * 8 * Time.deltaTime;
			}
			targetsInSecondSkill= targets.FindAll(bot => Mathf.Abs(bot.position.x-myPlayer.transform.position.x)<=1.0f && Mathf.Abs(bot.position.y-myPlayer.transform.position.y)<=0.6f);
			foreach(Transform x in targetsInSecondSkill)
			{
				if(!targetsDamagedSecondSkill.Contains(x))
				{
					AIscript = (AI)x.GetComponent("AI");
					AIscript.AddJustCurrHealth(-15);
					targetsDamagedSecondSkill.Add(x);
				}
			}
			ttlSecondSkill-=Time.deltaTime;
		}
		if (ttlSecondSkill<=0)
		{
			targetsDamagedSecondSkill.Clear();
		}
		//
		//
		if (Input.GetKeyDown(KeyCode.C) && NGUITools.GetActive(inventory) && myPlayer.GetComponent<GUI_Inv>().stats == 40 && !NGUITools.GetActive(gameObject.GetComponent<Shops>().shop)){
			NGUITools.SetActive (inventory, false);
			checkAudio=false;
		}
		else if(Input.GetKeyDown(KeyCode.C) && !NGUITools.GetActive(inventory)){
			NGUITools.SetActive (inventory, true);
		}
		//Stats
		//Debug.Log(_VitL.color);
		if(_vitalityI>0){
			_VitL.color = new Color(0,1,0,1);
		}else{
			_VitL.color = new Color(1,1,1,1);
		}
		if(_agilityI>0){
			_AgL.color = new Color(0,1,0,1);
		}else{
			_AgL.color = new Color(1,1,1,1);
		}
		if(_intelligenceI>0){
			_IntL.color =new Color(0,1,0,1);
		}else{
			_IntL.color =new Color(1,1,1,1);
		}
		VitalityTotal=Vitality+_vitalityI;
		AgilityTotal=Agility+_agilityI;
		IntelligenceTotal=Intelligence+_intelligenceI;
		VitalityL.text = Vitality.ToString();
		AgilityL.text = Agility.ToString();
		_VitL.text = _vitalityI.ToString();
		_IntL.text = _intelligenceI.ToString();
		_AgL.text = _agilityI.ToString();
		MaxHealth = VitalityTotal*18;
		MaxMana = IntelligenceTotal*16;
		maxSpeed = 4.0f+AgilityTotal*0.05f;
		maxSpeed = ((float)((int)(maxSpeed*100.0f))/100.0f);
		HealthReg = Mathf.Floor(VitalityTotal/5.0f);
		ManaReg = Mathf.Floor(IntelligenceTotal/5.0f);
		IntelligenceL.text = Intelligence.ToString();
		XP.sliderValue = (float)CurXP/(float)MaxXP;
		XpText.text = CurXP.ToString()+"/"+MaxXP.ToString();		
		HP.sliderValue = (float)CurHealth/(float)MaxHealth;
		HpText.text = CurHealth.ToString()+"/"+MaxHealth.ToString();
		MP.sliderValue = (float)CurMana/(float)MaxMana;
		MPText.text = CurMana.ToString()+"/"+MaxMana.ToString();
		Level.text = LVL.ToString();
		PointsL.text = Points.ToString();
		MS.text = maxSpeed.ToString();
		HPReg.text = ((int)HealthReg).ToString() + " hps";
		MPReg.text = ((int)ManaReg).ToString() + " mps";
		DamageWW = Damage + _damageW;
		DamageWWL.text = DamageWW.ToString();
		goldL.text = gold.ToString();
		
		
		if (CurXP>=MaxXP){
			CurXP=CurXP-MaxXP;
			MaxXP*=2;
			LVL+=1;
			Points+=4;
			NGUITools.SetActive(LevelUp,true);
			NGUITools.SetActive(LevelUpSe,true);
			done=true;
		}
		if (done && TimerLevel>0){
			TimerLevel-=Time.deltaTime;
		}
		if(done && TimerLevel<=0){
			NGUITools.SetActive(LevelUp,false);
			NGUITools.SetActive(LevelUpSe,false);
			TimerLevel=3.0f;
			done=false;
		}
		if (TimerRegen>0){
			TimerRegen-=Time.deltaTime;
		}
		if (TimerRegen<=0){
			if (CurHealth<MaxHealth){
				CurHealth+=(int)HealthReg;
				if(CurHealth>MaxHealth){
					CurHealth=MaxHealth;
				}
			}
			if (CurMana<MaxMana){
				CurMana+=(int)ManaReg;
				if(CurMana>MaxMana){
					CurMana=MaxMana;
				}
			}
			TimerRegen=1.0f;
		}
		if (NGUITools.GetActive(statsMenu) && !checkAudio){
			audio.PlayOneShot(gameObject.GetComponent<Sounds>().openPanel);
			checkAudio=true;
		}
		//		
    }