Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (lives > 0)
        {
            fruitTimer -= Time.deltaTime;

            if (fruitTimer < 0)
            {
                //Spawn fruit
                FruitScript    fruit         = Instantiate(fruitPrototype, new Vector3(Random.Range(-4f, 4f), 6), Quaternion.identity);
                SpriteRenderer fruitRenderer = fruit.GetComponent <SpriteRenderer>();

                switch (lives)
                {
                case 3:
                    fruitRenderer.color = Color.green;
                    break;

                case 2:
                    fruitRenderer.color = Color.yellow;
                    break;

                case 1:
                    fruitRenderer.color = Color.red;
                    break;
                }

                //Set timer again
                fruitTimer = Random.Range(minTimeBetweenFruit, maxTimeBetweenFruit); //Spawn fruit every 1-5 seconds
            }
        }
    }
Ejemplo n.º 2
0
    void Double(Collider other)    //双倍
    {
        FruitScript fruit = other.GetComponent <FruitScript>();

        try
        {
            fruit.Is_Double_Bool = true;
        }
        catch (Exception)
        {
        }

        if (other.gameObject.layer == MyTags.Fruit_Layer)
        {
            MeshRenderer render = null;


            render = other.transform.GetComponent <MeshRenderer> ();
            if (other.transform.GetComponent <FruitScript>().DoubleMaterial)
            {
                render.material = fruit.DoubleMaterial;
            }
            else
            {
                Debug.Log(other.name + "少个材质");
            }
        }
    }
Ejemplo n.º 3
0
 void Magnet(Collider other)    //磁铁
 {
     if (other.gameObject.layer == MyTags.Fruit_Layer)
     {
         FruitScript fruit = other.transform.GetComponent <FruitScript> ();
         //fruit.Target=this.transform.parent.transform.GetComponentInChildren<HumanColliderManager>().transform;
         fruit.Target = _nature.Human_Mesh;
     }
 }
Ejemplo n.º 4
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        string name = other.gameObject.name;

        if (name.StartsWith("apple") || name.StartsWith("banana"))
        {
            FruitScript script = other.gameObject.GetComponent <FruitScript>();
            script.Consume();
        }
    }
Ejemplo n.º 5
0
    private void OnTriggerEnter(Collider other)
    {
        FruitScript HitFruit = other.GetComponent <FruitScript>();

        Debug.Log(other.gameObject.name);
        if (HitFruit != null)
        {
            controller.OnFruitHit(HitFruit.currentFruitProp.Points);
        }
        else
        {
            controller.OnBoundaryHit();
        }
    }
Ejemplo n.º 6
0
    void Dash(Collider other)    //冲锋
    {
        switch (other.gameObject.layer)
        {
        case MyTags.Fruit_Layer:
            FruitScript fruit = other.transform.GetComponent <FruitScript> ();
            fruit.CutFruit();
            break;

        case MyTags.Obstacle_Layer:
            //播放音效
            MyAudio.PlayAudio(StaticParameter.s_Obstacle_Break, false, StaticParameter.s_Obstacle_Break_Volume);
            //Destroy (other.gameObject);
            try
            {
                StaticParameter.DestroyOrDespawn(other.transform);
                GameObject _obstacle = (GameObject)StaticParameter.LoadObject("Other", "BrokenObstacle");
                GameObject copy      = Instantiate(_obstacle, other.transform.position, Quaternion.identity) as GameObject;
                Destroy(copy, 2);

                SkinnedMeshRenderer huamnRenderer = other.transform.GetComponent <SkinnedMeshRenderer>();
                huamnRenderer.material.DOFade(0, 1);
            }
            catch (Exception)
            {
            }

            //摄像机震动
            CameraShake.Is_Shake_Camera = true;

            break;

        case MyTags.Spring_Layer:
            //播放音效
            MyAudio.PlayAudio(StaticParameter.s_Obstacle_Break, false, StaticParameter.s_Obstacle_Break_Volume);
            //摄像机震动
            CameraShake.Is_Shake_Camera = true;
            //播放破坏动画
            Animator ani = other.transform.GetComponent <Animator>();
            ani.SetBool(StaticParameter.Ani_Key_Broke, true);
            //摄像机震动
            CameraShake.Is_Shake_Camera = true;

            break;
        }
    }
Ejemplo n.º 7
0
    private void OnCollisionEnter(Collision collision)
    {
        // Checks to see if the weapon hit the fruit
        Debug.Log(velocity);

        if (collision.gameObject.tag == "Fruit")
        {
            FruitScript fruit = collision.gameObject.GetComponentInParent(typeof(FruitScript)) as FruitScript;

            // Add velocity requirement later
            if (fruit != null)
            {
                if (!fruit.IsDead())
                {
                    GetComponent <AudioSource>().Play();
                }
                fruit.killFruit();
            }
        }
    }
    private void Swap(FruitScript[] array, int firstIndex, int secondIndex)
    {
        FruitScript temp = array[firstIndex];

        array[firstIndex] = array[secondIndex];
        array[secondIndex] = temp;
    }
Ejemplo n.º 9
0
 // Start is called before the first frame update
 void Start()
 {
     Instance = this;
 }
Ejemplo n.º 10
0
 public Fruit(Transform fruit)
 {
     fruitScript = fruit.GetComponent <FruitScript> ();
     _collider   = fruit;
 }