/*移动完子节点位置后,才更新自己*/ public void MoveBody(SnakeNode node) { if (node == null) { return; } if (node.Previous != null) { node.MoveTo(node.Previous.Position); node.Previous.SetPosInfo(); this.tail.SetPosInfo(); } else { node.MoveTo(dest); } MoveBody(node.Next); }
//在尾部位置添加,并将尾部后移 public void AddBody(FRUITKIND fruitKind) { switch (fruitKind) { case FRUITKIND.Apple: isEatApple = true; effectbodyNum += 1; SnakeNode newTail = new SnakeNode(preFab, tail.Position, tail.Previous, tail); tail.Previous.SetNext(newTail); tail.SetPrevious(newTail); newTail.SetEffect(1.0f); tail.MoveTo(tail.Position - tail.Ob.transform.forward * scale); tail.SetPosInfo(); break; case FRUITKIND.Mango: SnakeNode newTail2 = new SnakeNode(preFab, tail.Position, tail.Previous, tail); tail.Previous.SetNext(newTail2); tail.SetPrevious(newTail2); if (isEatApple) { newTail2.SetEffect(1.0f); effectbodyNum += 1; } else { newTail2.SetColor(new Color(0.77f, 0.46f, 0.03f)); } tail.MoveTo(tail.Position - tail.Ob.transform.forward * scale); tail.SetPosInfo(); break; case FRUITKIND.Peach: SnakeNode newTail3 = new SnakeNode(preFab, tail.Position, tail.Previous, tail); tail.Previous.SetNext(newTail3); tail.SetPrevious(newTail3); if (isEatApple) { newTail3.SetEffect(1.0f); effectbodyNum += 1; } else { newTail3.SetColor(new Color(0.89f, 0.51f, 0.63f)); } tail.MoveTo(tail.Position - tail.Ob.transform.forward * scale); tail.SetPosInfo(); break; case FRUITKIND.Strawberry: SnakeNode newTail4 = new SnakeNode(preFab, tail.Position, tail.Previous, tail); tail.Previous.SetNext(newTail4); tail.SetPrevious(newTail4); if (isEatApple) { newTail4.SetEffect(1.0f); effectbodyNum += 1; } else { newTail4.SetColor(new Color(80, 0.0f, 0.23f)); } tail.MoveTo(tail.Position - tail.Ob.transform.forward * scale); tail.SetPosInfo(); break; case FRUITKIND.Watermelon: SnakeNode newTail5 = new SnakeNode(preFab, tail.Position, tail.Previous, tail); tail.Previous.SetNext(newTail5); tail.SetPrevious(newTail5); if (isEatApple) { newTail5.SetEffect(1.0f); effectbodyNum += 1; } else { newTail5.SetColor(new Color(0.06f, 0.42f, 0.23f)); } tail.MoveTo(tail.Position - tail.Ob.transform.forward * scale); tail.SetPosInfo(); break; default: break; } Win(); }