示例#1
0
 public void Fire()
 {
     if (timeSinceFire >= 60f / firePerMinute && foodHandler?.curFood > Mathf.Ceil(foodHandler.curFood * 0.1f))
     {
         Projectile projectile = Instantiate(projectilePrefab, muzzle.transform.position, Quaternion.identity);
         //Не подавать скейл, подавать число еды
         projectile.Init(aimingDirection, transform.root.localScale, Mathf.Ceil(foodHandler.curFood * 0.1f));
         foodHandler?.HandleFood(-Mathf.Ceil(foodHandler.curFood * 0.1f));
         timeSinceFire = 0f;
     }
 }
示例#2
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject)
        {
            FoodHandler foodhandler = collision.gameObject.GetComponent <FoodHandler>();
            if (foodhandler)
            {
                foodhandler.HandleFood(value);
                Destroy(gameObject);
            }
        }

        //Debug.Log(collision.gameObject);
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject)
        {
            FoodHandler foodHandler = collision.gameObject.GetComponent <FoodHandler>();
            if (foodHandler)
            {
                foodHandler.HandleFood(-foodCost * 2f);
            }
        }


        Destroy(gameObject);
    }
 private void OnCollisionStay2D(Collision2D collision)
 {
     if (collision.gameObject.CompareTag(targetTag))
     {
         //Debug.Log(collision.gameObject.name);
         FoodHandler foodHandler = collision.gameObject.GetComponent <FoodHandler>();
         if (foodHandler)
         {
             if (this.foodHandler.curFood > foodHandler.curFood)
             {
                 this.foodHandler.HandleFood(foodHandler.curFood);
                 foodHandler.HandleFood(-foodHandler.curFood);
                 //Debug.Log("Eaten");
             }
         }
     }
 }