protected void growParts() { snakeLength++; if (childScript == null) { if (front == null) { childPart = Instantiate(partToSpawn, transform.position + currentDirection * (-1.0f - distanceFactor) * myRenderer.bounds.size.x, Quaternion.identity); } else { childPart = Instantiate(partToSpawn, transform.position + currentDirection * (-distanceFactor) * myRenderer.bounds.size.x, Quaternion.identity); } childScript = childPart.GetComponentInChildren <SnakeBodyController>(); childScript.front = this; childScript.speed = speed; childScript.partToSpawn = partToSpawn; childScript.currentDirection = currentDirection; childScript.distanceFactor = distanceFactor; childScript.snakeLength = snakeLength; } else if (!gameSceneController.gameOver && childScript != null) //just in case the child object gets destroyed prior to this call { childScript.growParts(); } }
public override SnakeBody Init(Vector3 pos) { movePos = new Vector2(1, 0); bool isScience = MainGameManager.GameMode.IsScienceSkin; if (isScience) { GetComponent <SpriteRenderer>().sprite = Resources.Load <Sprite>("SnakePart/sh01"); } else { GetComponent <SpriteRenderer>().sprite = Resources.Load <Sprite>("SnakePart/sh02"); } snakeBodyCtrl = transform.parent .GetComponent <SnakeBodyController>().Init(isScience); return(base.Init(pos)); }
private void Awake() { RefrenceManager.getSingleton.snakeMovementControllerRefrence = this; snakeBodyController = new SnakeBodyController(this.totalBodyParts); startingPostition = this.transform.position; }