Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2020
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. [RequireComponent(typeof(Rigidbody2D))]
  4.  
  5. public class TapController : MonoBehaviour
  6. {
  7.  
  8. public delegate void PlayerDelegate();
  9. public static event PlayerDelegate OnPlayerDied;
  10. public static event PlayerDelegate OnPlayerScored;
  11.  
  12. public float tapForce = 10;
  13. public float tiltSmooth = 5;
  14. public Vector3 startPos;
  15.  
  16. Rigidbody2D rigidbody;
  17. Quaternion downRotation;
  18. Quaternion forwardRotation;
  19.  
  20.  
  21. void Start()
  22. {
  23. rigidbody = GetComponent<Rigidbody2D>();
  24. downRotation = Quaternion.Euler(0, 0, -90);
  25. forwardRotation = Quaternion.Euler(0, 0, 35);
  26.  
  27. }
  28.  
  29. void Update() {
  30.  
  31. if (Input.GetMouseButtonDown(0)){
  32. transform.rotation = forwardRotation;
  33. rigidbody.velocity = Vector3.zero;
  34. rigidbody.AddForce(Vector2.up * tapForce, ForceMode2D.Force);
  35. }
  36.  
  37. transform.rotation = Quaternion.Lerp(transform.rotation, downRotation, tiltSmooth * Time.deltaTime);
  38.  
  39. }
  40.  
  41. void onTriggerEnter2D(Collider2D col){
  42.  
  43. Debug.Log("Ooooh You touched ma badyyyy!");
  44.  
  45. if (col.gameObject.tag == "ScoreZone"){
  46. OnPlayerScored();
  47. }
  48.  
  49. if (col.gameObject.tag == "DeadZone"){
  50. Debug.Log("I HIT SOMETHING");
  51. rigidbody.simulated = false;
  52. OnPlayerDied();
  53. }
  54.  
  55. }
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement