Ejemplo n.º 1
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (!canMerge)
        {
            return;
        }
        var fruit = collision.collider.GetComponent <Fruit>();

        if (fruit != null && fruit.ID == this.ID && fruit.ID < 10)
        {
            if (fruit.transform.position.y >= transform.position.y)
            {
                return;
            }
            canMerge = false;
            rigidbody2D.simulated = false;
            fruit.GetComponent <Rigidbody2D>().simulated = false;
            transform.SetAsLastSibling();
            var targetPos = fruit.transform.position;
            transform.DOMove(targetPos, 0.1f).OnComplete(() =>
            {
                DestroyFruit();
                fruit.Recycle();
                var newFruit = oriFruitFactory.GetFruit(ID + 1);
                if (newFruit != null)
                {
                    newFruit.transform.SetParent(fruit.transform.parent);
                    newFruit.transform.localPosition = fruit.transform.localPosition;
                    newFruit.transform.localScale    = Vector3.one;
                }
                ScoreContro.Instance.AddScore(mergeExtraScore);
            });
        }
    }
Ejemplo n.º 2
0
 void Start()
 {
     //Elementos hijo del grid Food
     foreach (Transform t in foodGrid)
     {
         IFruit generatedFruit = eFactory.GetFruit((FruitTypes)generateRandomType());
         fruits.Add(generatedFruit);
         generatedFruit.setSprite(t.gameObject);
     }
 }
Ejemplo n.º 3
0
    public void SpawnFruit()
    {
        int     random    = Random.Range(0, 4);
        Vector3 randomPos = new Vector3(Random.Range(-1080 / 2, 1080 / 2), 1000, 0);
        var     fruit     = fruitFactory.GetFruit(random);

        fruit.transform.SetParent(fruitCanvas.transform);
        //fruit.transform.localPosition = randomPos;
        fruit.transform.localPosition = new Vector3(0, 1000, 0);
        fruit.transform.localScale    = Vector3.one;
        fruit.GetComponent <Rigidbody2D>().simulated = false;
        waitForFallFruit = fruit;
    }