public void CheckEat(SnakeNode _snake, List <Fruit> _fruits) { for (int i = 0; i < _fruits.Count; i++) { float dis = Vector3.Distance(_snake.GetPosition(), _fruits[i].GetPosition()); if (dis <= 1.0f) { if (SnakeNode.AteRainbow == true) { _snake.Grow(Color.white, colorTexture); } else { if (_fruits[i].GetTexture() != null) { SnakeNode.AteRainbow = true; _snake.EatFood(fruits[i]); } else { _snake.Grow(Color.gray, null); } } _fruits[i].DestroyFruit(); _fruits.RemoveAt(i); Debug.Log(fruits.Count); } } }
private void Follow(SnakeNode _node, Vector3 _pos) { if (_node == null) { return; } Follow(_node.NextNode, _node.SnakeObj.transform.position); _node.SnakeObj.transform.position = _pos; }
public void Grow(Color _color, Texture _texture) { if (this.NextNode == null) { this.NextNode = new SnakeNode(SnakeObj, SnakeObj.transform.position, _color, _texture); } else { this.NextNode.Grow(_color, _texture); } }
//-----------------------------------函数------------------------------------------ void CreateSnake() { snakehead = new SnakeNode(snakePrefab, new Vector3(3, 0.5f, 0), Color.red, null); snakehead.Grow(Color.gray, null); //body snakehead.Grow(new Color(148, 0, 211), null); //tail }