void OnTriggerEnter2D(Collider2D other) { if (allowed) { anim.SetTrigger("jump"); Debug.Log("Saute !"); } else { if (poitsukka.goesRight == false) { poitsukka.allowedLeft = false; TouchInput.allowedLeft = false; } else { poitsukka.allowedRight = false; TouchInput.allowedRight = false; } poitsukka.Idle(); textManager.DisplayMessage(message, textColor, delay); } Debug.Log(TouchInput.allowedLeft); }
// Update is called once per frame void Update() { dist = Vector2.Distance(poitsukkaPos.transform.position, destinationLocation); //J'ai touché quelque chose if (allowedToMove) { if (Input.touchCount == 1) { if (Mathf.Abs(poitsukkaPos.transform.position.x - checkpoints[destMod].transform.position.x) < 1) { if (destination < reachedCheckPoint) { reachedCheckPoint = reachedCheckPoint - 1; } else { reachedCheckPoint = reachedCheckPoint + 1; } reachedMod = reachedCheckPoint % nbCheckpoints; reachedOrder = checkpoints[reachedMod].GetComponent <SpriteRenderer>().sortingOrder; trunc.GetComponent <SpriteRenderer>().sortingOrder = checkpoints[destMod].GetComponent <SpriteRenderer>().sortingOrder; //sortOrder(checkpoints[destMod].GetComponent<SpriteRenderer>().sortingOrder); } if (interacting == false && dragging == false) { if (Input.GetTouch(0).position.x < Screen.width / 5 && Input.GetTouch(0).position.x > Screen.width / 8 && allowedLeft) { destination = reachedCheckPoint - 1; if (destination < 0) { destination = nbCheckpoints - 1; reachedCheckPoint = nbCheckpoints; } destMod = destination % nbCheckpoints; destinationLocation = checkpoints[destMod].transform.position; goToGoal(-1, destinationLocation, checkpoints[reachedMod].transform.position, 0); a.speed = -450; } else if (Input.GetTouch(0).position.x > Screen.width * 4 / 5 && Input.GetTouch(0).position.x < Screen.width * 7 / 8 && allowedRight) { destination = reachedCheckPoint + 1; if (destination < 0) { destination = nbCheckpoints - 1; reachedCheckPoint = nbCheckpoints; } destMod = destination % nbCheckpoints; destinationLocation = checkpoints[destMod].transform.position; goToGoal(1, destinationLocation, checkpoints[reachedMod].transform.position, 0); a.speed = 450; } else if (Input.GetTouch(0).position.x > Screen.width * 7 / 8 && allowedRight) { destination = reachedCheckPoint + 1; if (destination < 0) { destination = nbCheckpoints - 1; reachedCheckPoint = nbCheckpoints; } destMod = destination % nbCheckpoints; destinationLocation = checkpoints[destMod].transform.position; goToGoal(1, destinationLocation, checkpoints[reachedMod].transform.position, 1); a.speed = 900; } else if (Input.GetTouch(0).position.x < Screen.width / 8 && allowedLeft) { destination = reachedCheckPoint - 1; if (destination < 0) { destination = nbCheckpoints - 1; reachedCheckPoint = nbCheckpoints; } destMod = destination % nbCheckpoints; destinationLocation = checkpoints[destMod].transform.position; goToGoal(-1, destinationLocation, checkpoints[reachedMod].transform.position, 1); a.speed = -900; } else { poitsukkaScript.Idle(); a.speed = 0; } } } else if (Input.anyKey) { if (Mathf.Abs(poitsukkaPos.transform.position.x - checkpoints[destMod].transform.position.x) < 1) { if (destination <= reachedCheckPoint) { reachedCheckPoint = reachedCheckPoint - 1; if (reachedCheckPoint < 0) { reachedCheckPoint = nbCheckpoints - 1; destination = nbCheckpoints; } } else { reachedCheckPoint = reachedCheckPoint + 1; } reachedMod = reachedCheckPoint % nbCheckpoints; reachedOrder = checkpoints[reachedMod].GetComponent <SpriteRenderer>().sortingOrder; trunc.GetComponent <SpriteRenderer>().sortingOrder = checkpoints[destMod].GetComponent <SpriteRenderer>().sortingOrder; //sortOrder(checkpoints[destMod].GetComponent<SpriteRenderer>().sortingOrder); } if (interacting == false && dragging == false) { if (Input.GetKey("left") && allowedLeft) { destination = reachedCheckPoint; destMod = destination % nbCheckpoints; destinationLocation = checkpoints[destMod].transform.position; goToGoal(-1, destinationLocation, checkpoints[reachedMod].transform.position, 0); a.speed = -450; } else if (Input.GetKey("right") && allowedRight) { destination = reachedCheckPoint + 1; if (destination < 0) { destination = nbCheckpoints - 1; reachedCheckPoint = nbCheckpoints; } destMod = destination % nbCheckpoints; destinationLocation = checkpoints[destMod].transform.position; goToGoal(1, destinationLocation, checkpoints[reachedMod].transform.position, 0); a.speed = 450; } else if (Input.GetKey(KeyCode.RightControl) && allowedRight) { destination = reachedCheckPoint + 1; if (destination < 0) { destination = nbCheckpoints - 1; reachedCheckPoint = nbCheckpoints; } destMod = destination % nbCheckpoints; destinationLocation = checkpoints[destMod].transform.position; goToGoal(1, destinationLocation, checkpoints[reachedMod].transform.position, 1); a.speed = 900; } else if (Input.GetKey(KeyCode.LeftControl) && allowedLeft) { destination = reachedCheckPoint; destMod = destination % nbCheckpoints; destinationLocation = checkpoints[destMod].transform.position; goToGoal(-1, destinationLocation, checkpoints[reachedMod].transform.position, 1); a.speed = -900; } else { poitsukkaScript.Idle(); a.speed = 0; } } } else { poitsukkaScript.Idle(); a.speed = 0; } } }