Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- [RequireComponent(typeof(Rigidbody2D))]
- public class TapController : MonoBehaviour
- {
- public delegate void PlayerDelegate();
- public static event PlayerDelegate OnPlayerDied;
- public static event PlayerDelegate OnPlayerScored;
- public float tapForce = 10;
- public float tiltSmooth = 5;
- public Vector3 startPos;
- Rigidbody2D rigidbody;
- Quaternion downRotation;
- Quaternion forwardRotation;
- void Start()
- {
- rigidbody = GetComponent<Rigidbody2D>();
- downRotation = Quaternion.Euler(0, 0, -90);
- forwardRotation = Quaternion.Euler(0, 0, 35);
- }
- void Update() {
- if (Input.GetMouseButtonDown(0)){
- transform.rotation = forwardRotation;
- rigidbody.velocity = Vector3.zero;
- rigidbody.AddForce(Vector2.up * tapForce, ForceMode2D.Force);
- }
- transform.rotation = Quaternion.Lerp(transform.rotation, downRotation, tiltSmooth * Time.deltaTime);
- }
- void onTriggerEnter2D(Collider2D col){
- Debug.Log("Ooooh You touched ma badyyyy!");
- if (col.gameObject.tag == "ScoreZone"){
- OnPlayerScored();
- }
- if (col.gameObject.tag == "DeadZone"){
- Debug.Log("I HIT SOMETHING");
- rigidbody.simulated = false;
- OnPlayerDied();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement