Just trying to use AddForce to add an upwards force to an instantiated sphere. Must be something I'm leaving out or not coding properly. Here's my code. Note: touchLength is a variable which will have a value between 1 and 250, usually closer to 250.
void Update ()
{
if (Input.touchCount == 1)
{
if (Input.GetTouch(0).phase == TouchPhase.Ended)
{
//create sphere
GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
//add a rigidbody
Rigidbody spheresRigidBody = sphere.AddComponent();
//add mass
spheresRigidBody.mass = 5;
//fling sphere
sphere.rigidbody.AddForce(new Vector3(0, touchLength, 0));
}
}
}
↧