//三节身体小蛇 public Snake(GameObject _prefab, Vector3 _pos, Vector3 _dir, float _moveSpan, float _moveWait, float _scale, Control _controller) : base(_prefab, _pos, null, null) { active = false; controller = _controller; preFab = _prefab; this.direction = _dir; this.moveSpan = _moveSpan; this.moveWait = _moveWait; this.dest = direction * moveSpan + Position; this.timer = _moveWait; this.scale = _scale; this.Ob.name = "head"; this.SetColor(new Color(0.3f, 0.1f, 0.1f)); bodyBegain = new SnakeNode(_prefab, this.Position - this.Ob.transform.forward * _scale, this, null); bodyBegain.SetColor(Color.gray); bodyBegain.Ob.name = "bodybegain"; tail = new SnakeNode(_prefab, bodyBegain.Ob.transform.position - bodyBegain.Ob.transform.forward * _scale, bodyBegain, null); tail.Ob.name = "tail"; tail.SetColor(new Color(0.3f, 0.0f, 0.3f)); this.SetNext(bodyBegain); bodyBegain.SetNext(tail); //Component Ob.AddComponent <SnakeCollision>(); //Bodynum & Effected effectbodyNum = 0; }
//在尾部位置添加,并将尾部后移 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(); }