public GameObject Player; //player prefab
    public Vector2 PlayerPos; //player now position
    public GameObject Ground; //ground prefab
    public Text ScoreText;
    public int Score;
    public Sprite PlayerSkin; 
    private Rigidbody2D _playerR;
    private List<GameObject> _grounds = new List<GameObject>();
    private List<GameObject> _cacheGrounds = new List<GameObject>();
    void Awake()
    {
        PlayerPos = new Vector2(0.05F, 0.2F);
        Player = Instantiate(Ground, PlayerPos, Ground.transform.rotation)as GameObject;
        SpriteRenderer _player = Player.GetComponent<SpriteRenderer>();
        _player.color = Color.white;
        _playerR = _player.gameObject.AddComponent<Rigidbody2D>();
        _playerR.isKinematic = true;
        _player.sprite = PlayerSkin;
        _player.gameObject.transform.localScale = new Vector3(0.2F, 0.2F, 0.2F);
        InstantiateGround();
        InvokeRepeating(“SetDirection”, 0.1F,5); //设置方向
    }
    void Update ()
    {
        if (!GameOver)
        {
            if (Input.GetKeyDown(KeyCode.A))
            {
                timer = 0;
                PlayerPos = new Vector2(PlayerPos.x – 0.15f, PlayerPos.y);
                Player.transform.position = PlayerPos;
                SetPos();
            }
            else if (Input.GetKeyDown(KeyCode.D))
            {
                timer = 0;
                PlayerPos = new Vector2(PlayerPos.x + 0.15f, PlayerPos.y);
                Player.transform.position = PlayerPos;
                SetPos();
            }
        }
        if (TheTiming)
        {
            timer += Time.deltaTime;
            if (timer >= 0.4f)
            {
                _playerR.isKinematic = false;
                GameOver = true;
            }
        }
    }
    void SetPos()
    {
        _grounds[0].gameObject.GetComponent<Rigidbody2D>().isKinematic = false;
        _landfill.Add(_grounds[0]);
        _grounds.RemoveAt(0);
        Invoke(“RecoveryGround”, 2); //回收地面
      
        for (int i = 0; i < _grounds.Count; i++)
        {
            _grounds[i].transform.position = new Vector2(_grounds[i].transform.position.x, _grounds[i].transform.position.y – 0.15F);
        }
        Shake.shake.SetObj(_grounds[0].transform);
        if (float.Parse(PlayerPos.x.ToString(“N2”)) != float.Parse(_grounds[0].transform.position.x.ToString(“N2”)))
        {
            _playerR.isKinematic = false;
            GameOver = true;
        }
        else
        {
            Score += 1;
            ScoreText.text = “oh~ “ + Score.ToString();
        }
       
        InstantiateGround();
        TheTiming = true;
    }
    void RecoveryGround()
    {
        if (_landfill.Count > 0)
        {
            var res = _landfill.FindAll(M => M.transform.position.y < -1);
            foreach (var i in res)
            {
                i.gameObject.GetComponent<Rigidbody2D>().isKinematic = true;
                _cacheGrounds.Add(i);
                _landfill.Remove(i);
            }
        }
    }
    void SetDirection()
    {
        float _d = Random.Range(0, 1);
        if (_d > 0.5)
            _direction = -1;
        else if (_d < 0.5)
            _direction = 1;
    }
    void InstantiateGround()
    {
        //Add+y0.15
        //left -x 0.15
        //left +x 0.15
        GameObject go = null;
        for (int i = _grounds.Count; i < 25; i++)
        {
            if (_grounds.Count <= 0)
                go = Instantiate(Ground) as GameObject;
            else
            {
                if (_direction < 0)
                {
                    newPos = new Vector2(_grounds[i – 1].transform.position.x – 0.15f, _grounds[i – 1].transform.position.y + 0.15f);
                    if (newPos.x < -0.65f)
                    {
                        newPos = new Vector3(newPos.x + 0.3f, newPos.y);
                        _direction = 1;
                    }
                }
                else if (_direction > 0)
                {
                    newPos = new Vector2(_grounds[i – 1].transform.position.x + 0.15f, _grounds[i – 1].transform.position.y + 0.15f);
                    if (newPos.x > 0.65f)
                    {
                        newPos = new Vector3(newPos.x – 0.3f, newPos.y);
                        _direction = -1;
                    }
                }
                if (_cacheGrounds.Count > 0)
                {
                    go = _cacheGrounds[0];
                    _cacheGrounds.RemoveAt(0);
                    go.transform.position = newPos;
                }
                else
                    go = Instantiate(Ground, newPos, Ground.transform.rotation) as GameObject;
            }
            if (go.gameObject.GetComponent<Rigidbody2D>() == null)
                go.gameObject.AddComponent<Rigidbody2D>().isKinematic = true;
            SpriteRenderer _groundSprite = go.GetComponent<SpriteRenderer>();
            _groundSprite.sprite =_groundSprites[Random.Range(0, _groundSprites.Count-1)];
            _grounds.Add(go);
        }
    }