void OnTriggerEnter2D(Collider2D coll) { // Food? if (coll.name.StartsWith("Food")) { // Get longer in next Move call ate = true; Destroy(coll.gameObject); // Remove the Food blinkSnake.getBlink(5); ScoreVal++; } else { isDied = true; } }
void Update() { score.NewKey(ScoreVal.ToString()); if (!isDied) { if (Input.inputString == rightKey) { dir = Vector2.right; blinkRight.getBlink(1); rightKey = RandControl(rightKey); if (rightKey == downKey || rightKey == leftKey || rightKey == upKey) { rightKey = RandControl(rightKey); } dispRight.NewKey(rightKey); } else if (Input.inputString == downKey) { dir = -Vector2.up; // '-up' means 'down' blinkDown.getBlink(1); downKey = RandControl(downKey); if (downKey == rightKey || downKey == leftKey || downKey == upKey) { downKey = RandControl(downKey); } dispDown.NewKey(downKey); } else if (Input.inputString == leftKey) { dir = -Vector2.right; // '-right' means 'leftKey' blinkLeft.getBlink(1); leftKey = RandControl(leftKey); if (leftKey == rightKey || leftKey == downKey || leftKey == upKey) { leftKey = RandControl(leftKey); } dispLeft.NewKey(leftKey); } else if (Input.inputString == upKey) { dir = Vector2.up; blinkUp.getBlink(1); upKey = RandControl(upKey); if (upKey == rightKey || upKey == downKey || upKey == leftKey) { upKey = RandControl(upKey); } dispUp.NewKey(upKey); } } else { if (Input.GetKey(KeyCode.R)) { //clear the tail tail.Clear(); //reset to origin transform.position = new Vector3(0, 0, 0); //make snake alive isDied = false; } } }