public class ball_Input : MonoBehaviour {
Ray ry;
public float distanceunits=100;
public GameObject basketBall;
public bool isHit=false;
// Update is called once per frame
RaycastHit hit;
void Update () {
ry = Camera.main.ScreenPointToRay (Input.mousePosition);
//Vector3 positon = ray.GetPoint (distanceunits);
if(Physics.Raycast(ry,out hit,distanceunits))
{
//Debug.Log (hit.transform.gameObject.name);
isHit=true;
}
}
void FixedUpdate()
{
if ((isHit == true)) {//&&(Input.GetMouseButtonDown(0))
basketBall.rigidbody.AddForceAtPosition(new Vector3(0,30,0),hit.transform.position);
isHit = false;
Debug.Log("Clciked");
}
}
}
I have attached this code to my main camera .I am begginer so i am making a simple program where the ball jumps whenever i click it,so far i have succeded in adding a force to the sphere , i cant get it add force only on mouseclick and also i would like to add force that makes the ball go different angles based on the point i click it (z axis not needed) Help