public float horizontalCollisions(float deltaY, float deltaX, Vector2 p) { // Check collisions left and right movementStopped = false; for (int i = 0; i < 3; i++) { float dir = Mathf.Sign(deltaX); float x = p.x + c.x + s.x / 2 * dir; float y = p.y + c.y - s.y / 2 + s.y / 2 * i; ray = new Ray(new Vector2(x, y), new Vector2(dir, 0)); Debug.DrawRay(ray.origin, ray.direction); if (Physics.Raycast(ray, out hit, Mathf.Abs(deltaX) + skin, collisionMask)) { // Get Distance between player and ground float dst = Vector3.Distance(ray.origin, hit.point); // Stop player's downwards movement after coming within skin width of a collider if (dst > skin) { deltaX = dst * dir - skin * dir; } else { deltaX = 0; } movementStopped = true; break; } else if (Physics.Raycast(ray, out hit, Mathf.Abs(deltaX) + skin, collectableMask)) { string name = hit.collider.gameObject.name.Substring(0,7); //Debug.Log("!!!Try to pass name: " + name); if (running.isHitItem(name)) { Animator animator = hit.collider.gameObject.GetComponent<Animator>(); animator.SetBool("eaten", true); //GameObject.Destroy(hit.collider.gameObject); } } else if (Physics.Raycast(ray, out hit, Mathf.Abs(deltaX) + skin, endFlagMask)) { if(collider.gameObject.ToString().CompareTo("Player_sprite(Clone)") > 0){ PlayerPrefs.SetInt ("Win", -1); PlayerPrefs.SetString ("Winning Time", ""); GameObject mainObject = GameObject.Find ("MainObject"); RRConnectionManager cManager; cManager = RRConnectionManager.getInstance (); RequestRREndGame requestRREndGame = new RequestRREndGame (); requestRREndGame.Send (Running.completed, Running.time.ToString ()); cManager.Send (requestRREndGame); doPlayerFinish(); } } } return deltaX; }
public float horizontalCollisions(float deltaY, float deltaX, Vector2 p) { // Check collisions left and right movementStopped = false; for (int i = 0; i < 3; i++) { float dir = Mathf.Sign(deltaX); float x = p.x + c.x + s.x / 2 * dir; float y = p.y + c.y - s.y / 2 + s.y / 2 * i; ray = new Ray(new Vector2(x, y), new Vector2(dir, 0)); Debug.DrawRay(ray.origin, ray.direction); if (Physics.Raycast(ray, out hit, Mathf.Abs(deltaX) + skin, collisionMask)) { // Get Distance between player and ground float dst = Vector3.Distance(ray.origin, hit.point); // Stop player's downwards movement after coming within skin width of a collider if (dst > skin) { deltaX = dst * dir - skin * dir; } else { deltaX = 0; } movementStopped = true; break; } else if (Physics.Raycast(ray, out hit, Mathf.Abs(deltaX) + skin, collectableMask)) { string name = hit.collider.gameObject.name.Substring(0, 7); //Debug.Log("!!!Try to pass name: " + name); if (running.isHitItem(name)) { Animator animator = hit.collider.gameObject.GetComponent <Animator>(); animator.SetBool("eaten", true); //GameObject.Destroy(hit.collider.gameObject); } } else if (Physics.Raycast(ray, out hit, Mathf.Abs(deltaX) + skin, endFlagMask)) { if (collider.gameObject.ToString().CompareTo("Player_sprite(Clone)") > 0) { PlayerPrefs.SetInt("Win", -1); PlayerPrefs.SetString("Winning Time", ""); GameObject mainObject = GameObject.Find("MainObject"); ConnectionManager cManager; cManager = mainObject.GetComponent <ConnectionManager> (); RequestRREndGame requestRREndGame = new RequestRREndGame(); requestRREndGame.Send(Running.completed, Running.time.ToString()); cManager.Send(requestRREndGame); doPlayerFinish(); } } } return(deltaX); }