Advertisement
WPDeveloper

ColiderProblem

Jan 3rd, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Bola : MonoBehaviour {
  5.  
  6.     public Rigidbody2D corpoDaBola;
  7.     public Rigidbody2D PlayerUm;
  8.     public float VelBolax;
  9.     public float VelBolay;
  10.  
  11.     // Use this for initialization
  12.     void Start () {
  13.         PlayerUm = GetComponent<Rigidbody2D> ();
  14.         corpoDaBola = GetComponent<Rigidbody2D> ();
  15.         corpoDaBola.AddForce (new Vector2(0.05f,0.05f));
  16.     }
  17.    
  18.     // Update is called once per frame
  19.     void Update () {
  20.         VelBolax = corpoDaBola.velocity.x;
  21.         VelBolay = corpoDaBola.velocity.y;
  22.     }
  23.  
  24.     void OnCollisionEnter2D (Collision2D colisao){
  25.  
  26.         if ((colisao.gameObject.tag == "Player")){
  27.  
  28.             if ((VelBolax < 19f) && (VelBolax > -19f) && (VelBolay < 19f) && (VelBolay > -19f)) {
  29.                 corpoDaBola.velocity = corpoDaBola.velocity + PlayerUm.velocity / 10;
  30.             }
  31.         }
  32.  
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement