Advertisement
Guest User

Untitled

a guest
Oct 27th, 2015
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.69 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class BallControl : MonoBehaviour {
  5.  
  6.     int waitSeconds = 2;
  7.  
  8.     // Use this for initialization.
  9.     void Start ()
  10.     {
  11.         hi(20f);
  12.         GoBall();
  13.     }
  14.  
  15.     IEnumerator hi(float secs)
  16.     {
  17.         yield return new WaitForSeconds(secs);
  18.     }
  19.    
  20.     // Generates random value, and decides which way to knock the ball based on it.
  21.     void GoBall ()
  22.     {
  23.         float rand = Random.Range(0.0f, 100.0f);
  24.  
  25.         if (rand < 50.0f)
  26.         {
  27.             Rigidbody2D.AddForce(new Vector2(20.0f, 15.0f));
  28.         }
  29.  
  30.         else
  31.         {
  32.             Rigidbody2D.AddForce(new Vector2(-20.0f, -15.0f));
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement