//does Kevins work but appeals to touch controls for the specific minigame void SwipeLine() { //if there is touch input if (Input.touchCount == 1) { //get that touch input Touch touch = Input.GetTouch(0); switch (touch.phase) { //if the touch has began case TouchPhase.Began: { //store that start position m_touchBegin = touch.position; } break; //if the touch has ended case TouchPhase.Ended: { //store the end position m_touchEnd = touch.position; var ray2 = Camera.main.ScreenPointToRay(m_touchBegin); Vector2 directionPreNorm = (m_touchEnd - m_touchBegin); m_swipeDirection = (m_touchEnd - m_touchBegin); m_swipeDirection = NegativePositiveFunction(m_swipeDirection); //normalize m_swipeDirection.Normalize(); //check for multiple hits from a raycast and store them RaycastHit2D[] hit = Physics2D.RaycastAll(ray2.origin, m_swipeDirection, m_swipeDirection.magnitude); //for everything hit by the raycast for (int i = 0; i < hit.Length; i++) { //check if any of them are plants, if they are if (hit[i].collider.tag == "Plant") { //Get that plants script and set it to swiped PlantScriptManager tempPlantScript = hit[i].collider.gameObject.GetComponent <PlantScriptManager>(); //add the plants score to the list of scores m_plantScore.Add(tempPlantScript.Swiped(out plantHit)); //add the plants score to the list of scores //m_plantScore.Add(tempPlantScript.Swiped()); //if the plant hit is a debuff plant (lightning plant if (plantHit is DebuffPlant) { //Upcase the baseplant to debuff plant since we're sure it's a debuffplant DebuffPlant tempPlant = plantHit as DebuffPlant; //if the debuff plants lightning is active if (tempPlant.GetLightning()) { //lock out swiping for 2 seconds bSwipeLockout = true; } //else else { //do nothing } } } } //for each score swiped for (int i = 0; i < m_plantScore.Count; i++) { //add that to the game score (DO SOMETHING FUNKY WITH MULTIPLIERS HERE) m_combinedScore += m_plantScore[i]; } //m_combinedScore *= m_plantScore.Count; //Create float text feedback numbers FloatingTextManager.CreateFloatingText(m_combinedScore.ToString(), Player1.transform); //increment the local players score if (LocalPlayerPortrait) { LocalPlayerPortrait.IncrementScore(m_combinedScore); } else { Player1Stats.IncrementScore(m_combinedScore); } //m_combinedScore *= m_plantScore.Count; //manager.IncrementScore(m_combinedScore); m_combinedScore = 0; m_plantScore.Clear(); } break; } } }
//mouse input class void OnTileClick() { //check if the mouse is down m_newMouseDown = Input.GetMouseButton(0); //if left mouse button is down if (m_newMouseDown == true && m_oldMouseDown == false) { swipe = Instantiate(Resources.Load("Minigames/PlantMinigame/Prefabs/Swipe") as GameObject); //shoot a ray from the mouse position to the screen m_StartDrag = Camera.main.ScreenToWorldPoint(Input.mousePosition); m_StartDrag.z = 0; } if (m_newMouseDown == true && m_oldMouseDown == true) { swipe.transform.position = new Vector3(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y, -5); } if (m_newMouseDown == false && m_oldMouseDown == true) { m_EndDrag = Camera.main.ScreenToWorldPoint(Input.mousePosition); m_EndDrag.z = 0; Vector2 direction = (m_EndDrag - m_StartDrag); direction = NegativePositiveFunction(direction); Vector2 directionPreNorm = direction; direction = direction.normalized; RaycastHit2D[] hits = Physics2D.RaycastAll(m_StartDrag, direction, directionPreNorm.magnitude); //check all the hits from the raycast for (int i = 0; i < hits.Length; i++) { //check if any of them are plants, if they are if (hits[i].collider.tag == "Plant") { //Get that plants script and set it to swiped PlantScriptManager tempPlantScript = hits[i].collider.gameObject.GetComponent <PlantScriptManager>(); //get plant component m_plantsHit.Add(tempPlantScript.GetPlantComponent()); m_plantScore.Add(tempPlantScript.Swiped(out plantHit)); //add the plants score to the list of scores //m_plantScore.Add(tempPlantScript.Swiped()); //if the plant hit is a debuff plant (lightning plant if (plantHit is DebuffPlant) { //Upcase the baseplant to debuff plant since we're sure it's a debuffplant DebuffPlant tempPlant = plantHit as DebuffPlant; //if the debuff plants lightning is active if (tempPlant.GetLightning()) { //lock out swiping for 2 seconds bSwipeLockout = true; } //else else { //do nothing } } } } //for (int i = 0; i < m_plantsHit.Count; i++) { // m_plantScore.Add (0); // int temp; // m_plantsHit [i].ActivatePlant (out temp); // m_plantScore [m_plantScore.Count-1] = temp; //} //for each score swiped for (int i = 0; i < m_plantScore.Count; i++) { //add that to the game score (DO SOMETHING FUNKY WITH MULTIPLIERS HERE) m_combinedScore += m_plantScore[i]; } //m_combinedScore *= m_plantScore.Count; //Create float text feedback numbers //FloatingTextManager.CreateFloatingText (m_combinedScore.ToString(), Player1.transform); //increment the local players score if (LocalPlayerPortrait) { LocalPlayerPortrait.IncrementScore(m_combinedScore); } else { m_portraitScripts [0].GetComponent <PortaitScript> ().IncrementScore(m_combinedScore); //GameObject.FindGameObjectWithTag("Portrait").GetComponent<PortaitScript>().IncrementScore (m_combinedScore); } m_combinedScore = 0; m_plantScore.Clear(); m_plantsHit.Clear(); } m_oldMouseDown = m_newMouseDown; }