Exemple #1
0
 // Update is called once per frame
 void Update()
 {
     if (selected) //if the user is currently using the handle
     {
         float x = Input.GetAxis("Mouse Y");
         x *= handleSpeed;
         float newPos = handle.localPosition.x + x;
         if (newPos < handleMaxX && newPos > handleMinX) //make sure it doesn't go past the start and end
         {
             Vector3 newVecPos = handle.localPosition;
             newVecPos.x          = newPos;
             handle.localPosition = newVecPos;
         }
     }
     else   // if the user isn't using the handle (potentially just released it)
     {
         velocity = (handleInit.x - handle.localPosition.x) * velocityFactor;
         if (ballScript.GetVelocity() == 0)       // if the ball is currently at rest
         {
             ballScript.SetDir(platform.forward); // set it's direction to the same as the platform
             ballScript.SetVelocity(velocity);    //give it the velocity that the platform traveled
         }
         handle.localPosition = handleInit;
     }
 }
Exemple #2
0
 // Update is called once per frame
 void Update()
 {
     if (ballScript.CheckForPass(transform))
     {
         float   d         = Vector3.Distance(transform.position, ball.transform.position);
         Vector3 onBarrier = ball.transform.position - (-transform.forward) * d;
         if (Vector3.Distance(onBarrier, transform.position) < transform.localScale.x / 1.2)
         {
             if (Vector3.Dot(ballScript.GetDir(), -transform.forward) < 0f)
             {
                 ball.transform.position = exitPoint.position;
                 ballScript.SetDir(-exitPoint.forward);
             }
         }
     }
 }