private void Shoot(Vector3 mousePos) { if (Input.GetMouseButtonDown(0) && timeStamp < Time.time) { NumberNode newNode = Instantiate(node, transform.position, Quaternion.identity, parentTransform).GetComponent <NumberNode>(); //newNode.SetValue(Random.Range(NumberList.BOUND_LOW, NumberList.BOUND_HIGH)); newNode.SetValue(2); newNode.SetState(NodeState.PROJECTILE); Vector3 heading = mousePos - transform.position; float distance = heading.magnitude; newNode.nodeController.SetDirection(heading / distance); timeStamp = Time.time + COOLDOWN; } }
void Update() { if (!GameStateManager.IsPaused()) { if (timeStamp < Time.time) { LayerMask nodeMask = LayerMask.GetMask("NodeLayer"); if (!Physics2D.OverlapCircle(transform.position, NumberNode.RADIUS, nodeMask)) { NumberNode newNode = Instantiate(numberBall, pathStart, Quaternion.identity, parentTransform).GetComponent <NumberNode>(); NodeManager.AddNode(newNode); newNode.SetState(NodeState.FORWARD); newNode.Init(); newNode.SetValue(Random.Range(NumberList.BOUND_LOW, NumberList.BOUND_HIGH)); timeStamp = Time.time + cooldown; } } } }
// 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(); } }