// Update is called once per frame void Update() { //For debug purpose if (restartGame) { restartGame = false; OnRestartButtonPressed(); } //Compare last pos update time and move snake if (Time.time > (lastUpdateTime + advancedSettings.nextMoveTime)) { Vector3 newPos = GetNewPos(); if (!gameOver) { m_headPos = newPos; if (CheckCollision()) { OnCollision(); return; } m_headMovementScript.Move(m_headPos, transform.localRotation.eulerAngles.z); lastUpdateTime = Time.time; } } }
public void Move(Vector3 newPos, float newZRot) { //If Snake part is there after this, invoke the movement for that part if (previousPartMovemt != null) { previousPartMovemt.Move(transform.localPosition, transform.localRotation.eulerAngles.y); } //Set new pos transform.localPosition = newPos; //Head rotation will be handled in Snake handler script itself if (snakeBodyType != SnakeBodyType.head) { transform.localRotation = Quaternion.Euler(0, 0, newZRot); } }