Пример #1
0
    private AnimalHealth GetClosest()
    {
        var health = COMPONENT_DATABASE.RetrieveComponents <AnimalHealth>();

        if (health.Count == 0)
        {
            return(null);
        }

        AnimalHealth closest     = null;
        float        closestDist = float.MaxValue;

        foreach (var ah in health)
        {
            float dist = (ah.gameObject.transform.position - transform.position).magnitude;

            if (dist < closestDist)
            {
                closest     = (AnimalHealth)ah;
                closestDist = dist;
            }
        }

        return(closest);
    }
Пример #2
0
    public override void SetTarget()
    {
        AnimalHealth closest = GetClosest();

        if (closest != null)
        {
            m_TargetAnimal = closest;
            target         = closest.transform;
        }
    }
Пример #3
0
    public void CharacterHpControll()
    {
        switch (playerManager.PossessType)
        {
        case "Human":
            PineHpMax = PlayerHealth.MaxHealth;
            PineHpNow = PlayerHealth.currentHealth;

            HpW.fillAmount = (PineHpNow * 0.75f + PineHpMax * 0.25f) / PineHpMax;    //(75%當前血量+25%血量最大值)/血量最大值
            HpR.fillAmount = (PineHpNow * 0.75f + PineHpMax * 0.25f) / PineHpMax;    //Ex:當前血20 血量最大值100 為 (20*75%+100*25%)/100 = 0.4
            break;

        case "Wolf":
            if (PossessedSystem.AttachedBody == this.gameObject)
            {
                AnimalHealth = GameObject.Find("Player/Wolf").GetComponent <AnimalHealth>();
                WolfHpMax    = AnimalHealth.MaxHealth;
                WolfHpNow    = AnimalHealth.currentHealth;

                HpW.fillAmount = (WolfHpNow * 0.75f + WolfHpMax * 0.25f) / WolfHpMax;
                HpR.fillAmount = (WolfHpNow * 0.75f + WolfHpMax * 0.25f) / WolfHpMax;
            }
            break;
            //case "Bear":
            //    AnimalHealth = GameObject.Find("Player/Bear").GetComponent<AnimalHealth>();
            //    BearHpMax = AnimalHealth.MaxHealth;
            //    BearHpNow = AnimalHealth.currentHealth;
            //    HpB.fillAmount = (BearHpNow * 0.75f + BearHpMax * 0.25f) / BearHpMax;
            //    HpW.fillAmount = (BearHpNow * 0.75f + BearHpMax * 0.25f) / BearHpMax;
            //    HpR.fillAmount = (BearHpNow * 0.75f + BearHpMax * 0.25f) / BearHpMax;
            //    break;
            //case "Deer":
            //    AnimalHealth = GameObject.Find("Player/Deer").GetComponent<AnimalHealth>();
            //    DeerHpMax = AnimalHealth.MaxHealth;
            //    DeerHpNow = AnimalHealth.currentHealth;
            //    HpB.fillAmount = (DeerHpNow * 0.75f + DeerHpMax * 0.25f) / DeerHpMax;
            //    HpW.fillAmount = (DeerHpNow * 0.75f + DeerHpMax * 0.25f) / DeerHpMax;
            //    HpR.fillAmount = (DeerHpNow * 0.75f + DeerHpMax * 0.25f) / DeerHpMax;
            //    break;
        }
    }
Пример #4
0
	public void Update ()
	{


		gameObject.GetComponent<Rigidbody>().AddForce(transform.up * -1);
		

		for (int x=0; x<Targets.Count; x++) { //it will run trought each animal in the array

			if(Targets[x].activeInHierarchy==false)
			{
				Targets[x].tag = "Untagged";

			
				Targets.RemoveAt(x);
				Target=null;
			}

		}
	
		
		health ();

		//checks if the enemy is closer to the player... otherwise it must wander around or chase animals
		if (Vector3.Distance (Player.position, transform.position) <= LookAtDistance)
		{
			_distance = Vector3.Distance (Player.position, transform.position); //checks the distance between enemy and the player
			
			if (_distance < LookAtDistance) 
			{
				LookAt (Player);
			}
			
			if (_distance < ChaseRange && _distance > AttackRange) 
			{
				Chase ();
			}
			
			if (Vector3.Distance (Player.position, transform.position) < AttackRange && _distance != 0.0f) 
			{	
				Target=Player;
				Attack ();
			
			} 

			
		} 
		else if(Vector3.Distance (Player.position, transform.position) >LookAtDistance)//this is if the player is not close to the enemy
		{
			for (int x=0; x<Targets.Count; x++) //it will run trought each animal in the array
			{
					
				
				if(Targets[x].activeInHierarchy==true)//checks if the target is active
				if (Vector3.Distance (Targets [x].transform.position, transform.position) <= LookAtDistance) //checks the distance of which is the closest animal out of all
				{
					_distance = Vector3.Distance (Targets [x].transform.position, transform.position);//distance of that closest animal

					Target = Targets [x].transform;
				

					if (_distance < LookAtDistance) //if that distance is less than the look at distance then look at the animal
					{
						animwander.enabled = false; //de activate the script for animal wandering
						LookAt (Target);//look at the target
					}
				}
			}
			
			if (_distance < ChaseRange && _distance > AttackRange) 
			{
				animwander.enabled = false;
				Chase ();
			} 
			else if
				(_distance < AttackRange && _distance != 0.0f) 
			{
				if(Target!=null && Vector3.Distance (Target.position, transform.position)<AttackRange)
				{
				_animalHealth=Target.GetComponent<AnimalHealth>();

				animwander.enabled = false;
				if(_animalHealth.animalHealth>0)
				Attack ();
					isAttacking=true;
				}
				else
				{
					animwander.enabled = true;
					PlayIdle();
				}
			}
			else
			{
				animwander.enabled = true;
		//		Debug.Log ("call wandering script " + gameObject.name);
				PlayIdle ();
			}
		
		}
	}
Пример #5
0
 protected override void DoReset()
 {
     m_TargetAnimal = null;
     m_Killed       = false;
 }