Beispiel #1
0
    void OnTriggerEnter2D(Collider2D c)
    {
        if (c.gameObject.tag == "Food")
        {
            // 食べた?
            eat = true;

            // SE
            this.aud.PlayOneShot(this.eatSE);

            // 餌にぶつかると餌が消える
            FindObjectOfType <Score> ().AddPoint(point);
            Destroy(c.gameObject);
            spawnFood.Spawn();
        }
        else
        {
            // SE
            this.aud.PlayOneShot(this.gameOverSE);
            // Snakeタグのついたゲームオブジェクトを隠す
            snakes = GameObject.FindGameObjectsWithTag("Snake");
            foreach (GameObject snake in snakes)
            {
                snake.GetComponent <Renderer> ().enabled = false;
            }
            // コルーチン
            StartCoroutine("gameOver");

            // ハイスコアの保存
            //FindObjectOfType<Score> ().Save ();

            // シーン遷移
            //SceneManager.LoadScene ("GameOverScene");
        }
    }
Beispiel #2
0
    void OnTriggerEnter2D(Collider2D coll)
    {
        // Food?
        if (coll.tag.Equals("Snake_Food"))
        {
            // Get longer in next Move call
            ate = true;

            // Remove the Food
            Destroy(coll.gameObject);

            // Nieuw voedsels
            foodSpawner.Spawn();
        }
        else if (coll.tag.Equals("Snake_Wall") || coll.tag.Equals("Snake_Body"))
        {
            if (tail.Count > 0 && coll.gameObject == tail[0].gameObject)
            {
                return;
            }
            CancelInvoke("Move");

            GameOver.ShowGameOver(score);
        }
    }
Beispiel #3
0
    void Move()
    {
        // Move head in new direction
        Vector2 headPos = transform.position;

        transform.Translate(dir);

        // If eaten food
        if (ate)
        {
            GameObject tailPiece = (GameObject)Instantiate(tailPrefab, headPos, Quaternion.identity);
            // Insert new tail into tail list
            tailList.Insert(0, tailPiece.transform);
            script.Spawn();
            score++;
            ate = false;

            if (score == 1)
            {
                speed -= .02f;
            }
            else if (score > 1 && score < 5)
            {
                speed -= .01f;
            }
            else if (score > 4 && score < 13)
            {
                speed -= .005f;
            }
            else if (speed >= .05)
            {
                speed -= .001f;
            }
            Debug.Log(speed.ToString());
        }

        // If tail exists
        else if (tailList.Count > 0)
        {
            // Move last tail element to where head was
            tailList.Last().position = headPos;

            // Add to front of list, remove from back
            tailList.Insert(0, tailList.Last());
            tailList.RemoveAt(tailList.Count - 1);
        }
    }
    void OnTriggerEnter2D(Collider2D coll)
    {
        // Food?
        if (coll.name.StartsWith("FoodPrefab"))
        {
            // Get longer in next Move call
            ate = true;

            // Remove the Food
            Destroy(coll.gameObject);

            spawnFood.Spawn();
        }
        // Collided with Tail or Border
        else
        {
            // ToDo 'You lose' screen
        }
    }
Beispiel #5
0
 private void FirstSpawnFood()
 {
     spawnFood.Spawn(tail);
 }