示例#1
0
 //eat grass
 private void OnTriggerStay2D(Collider2D collision)
 {
     if (collision.gameObject.tag == "Field")
     {
         currField = collision.GetComponent <Cd_FieldGeneration>();
         if (HungerStateID == 2 && searchField.target.getGrowth() >
             30 && currField == searchField.target)
         {
             currField.eatTile(30);
             hunger += 50;
             //Debug.Log("FieldID is " + currField.gameObject.name);
             if (searchField.target.getGrowth() < 30)
             {
                 searchField.target = null;
             }
         }
     }
     if (collision.gameObject.tag == "Prey" && MateStateID == 1)
     {
         duration -= Time.deltaTime;
         if (duration <= 0)
         {//finished mating
             duration    = 0;
             MateStateID = 0;
             GameObject offspring = Instantiate(OffspringType);
             offspring.GetComponentInChildren <Cd_PreyBetas>().age         = 0;
             offspring.GetComponentInChildren <Cd_PreyBetas>().MateStateID = 0;
             offspring.GetComponentInChildren <Cd_PreyBetas>().eventSys    = eventSys;
             eventSys.enemyCount++;
         }
     }
 }
 private void OnTriggerStay2D(Collider2D collision)
 {
     if (collision.gameObject.tag == "Field")
     {
         temp = collision.GetComponent <Cd_FieldGeneration>();
         if (target)
         {
             if (temp.getGrowth() > target.getGrowth() + 30 && target.getGrowth() < 50)
             {
                 target = temp;
                 transform.localScale = new Vector3(1, 1, 1);
             }
         }
         else
         {
             target = temp;
         }
     }
 }