Advertisement
Guest User

Untitled

a guest
Dec 16th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Ball : MonoBehaviour
  6. {
  7. private Vector2 ballPosition;
  8. public Vector2 ballVelocity;
  9.  
  10. void Awake(){
  11. ballPosition = transform.position;
  12. }
  13.  
  14. // Update is called once per frame
  15. void Update()
  16. {
  17. ballPosition.y = transform.position.y + ballVelocity.y*Time.deltaTime;
  18. ballPosition.x = transform.position.x + ballVelocity.x*Time.deltaTime;
  19.  
  20. transform.position = new Vector3(ballPosition.x, ballPosition.y, transform.position.z);
  21. }
  22.  
  23. /// <summary>
  24. /// Sent when an incoming collider makes contact with this object's
  25. /// collider (2D physics only).
  26. /// </summary>
  27. /// <param name="other">The Collision2D data associated with this collision.</param>
  28. void OnCollisionEnter2D(Collision2D other)
  29. {
  30. if(other.gameObject.tag == "Muro"){
  31. ballVelocity.y *= -1;
  32. }else if(other.gameObject.tag == "EnemyGoal"){
  33. Debug.Log("Hemos marcado un gol");
  34. transform.position = new Vector3(0,0,0);
  35. ballVelocity.x = -3;
  36. ballVelocity.y = -2;
  37. }else if(other.gameObject.tag == "PlayerGoal"){
  38. Debug.Log("Eres un paquete");
  39. transform.position = new Vector3(0,0,0);
  40. ballVelocity.x = 3;
  41. ballVelocity.y = 2;
  42. }else if(other.gameObject.tag == "Pala"){
  43. ballVelocity.x *= -1.2f;
  44. }
  45. }
  46.  
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement