赞
踩
贪吃蛇 游戏是一款经典的手机游戏,既简单又耐玩。通过控制蛇头方向吃蛋,使得蛇变长,从而获取积分。
- void Update () {
- if (Input.GetKey(KeyCode.W)||Input.GetKey("up")&&direction!= Vector2.down)
- {
- direction = Vector2.up;
- }
- if (Input.GetKey(KeyCode.S) || Input.GetKey("down") && direction != Vector2.up)
- {
- direction = Vector2.down;
- }
- if (Input.GetKey(KeyCode.A) || Input.GetKey("left") && direction != Vector2.right)
- {
- direction = Vector2.left;
- }
- if (Input.GetKey(KeyCode.D) || Input.GetKey("right") && direction != Vector2.left)
- {
- direction = Vector2.right;
- }
-
- }
- void OnTriggerEnter(Collider other)
- {
- if (other.gameObject.CompareTag("Food"))
- {
- //Debug.Log("撞上了!");
- Destroy(other.gameObject);
- flag = true;
-
- }
- else
- {
- //SceneManager.LoadScene(0)
- Application.LoadLevel(1);
- }
- }
- void Move()
- {
- Vector3 VPosition = transform.position;
- transform.Translate(direction);
- if (flag)
- {
- GameObject bodyPrefab = (GameObject)Instantiate(gameObjecgtBody, VPosition, Quaternion.identity);
- Body.Insert(0, bodyPrefab.transform);
- flag = false;
- }
- else if (Body.Count > 0)
- {
- Body.Last().position = VPosition;
- Body.Insert(0, Body.Last());
- Body.RemoveAt(Body.Count - 1);
- }
- }
- void ShowFood()
- {
- int x = Random.Range(-30, 30);
- int y = Random.Range(-22, 22);
- Instantiate(SSFood, new Vector2(x,y), Quaternion.identity);
-
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。