private void SpawnNodeAtDistance(float distanceTravelled) { // Get the coordinates of the point at the distance travelled Vector3 pointOnPath = pathCreator.path.GetPointAtDistance(distanceTravelled); // Spawn a new node under the parent transform at those coordinates NumberNode newNode = Instantiate(numberBall, pointOnPath, Quaternion.identity, parentTransform).GetComponent <NumberNode>(); newNode.Init(); // Set the pathfollower's distance travelled acoordingly newNode.pathFollower.SetDistanceTravelled(distanceTravelled); // Set the node state to be in the gutter newNode.SetState(NodeState.GUTTER); // Disable the node's motor as the pathfollower takes care of movement in the gutter newNode.nodeMotor.enabled = false; newNode.SetColorToValue(); // Add the node to the node manager NodeManager.AddNode(newNode); }
// Instantiates a new node and fires it towards the mouse position. private void Shoot(Vector3 mousePos) { // Only accept shooting when we're in Pre-insertion if (GameStateManager.GetGameState() == GameState.PREINSERTION) { // Create a new node newNode = Instantiate(nodePrefab, transform.position, Quaternion.identity, parentTransform).GetComponent <NumberNode>(); // Get the directional vector towards the mouse position Vector3 heading = mousePos - transform.position; newNode.nodeMotor.SetDirection(heading.normalized); // Set the node state newNode.SetState(NodeState.PROJECTILE); // Set it's value and it's corresponding color int ballValue = NodeManager.GetNextBallValue(); newNode.SetValue(ballValue); newNode.SetColorToValue(); particles.setNode(newNode); // Let the gamestate manager know we're shooting now GameStateManager.SwitchToShooting(); } }