- Home /
How prevent addforce when clicking resume button?
I am making a game and the player can pick up and throw a ball by clicking the left mouse button. The problem is that when you click resume game the ball is also thrown. Here is my script using UnityEngine; using System.Collections;
public class throwx : MonoBehaviour {
public Rigidbody rb;
public Transform t_Camera; // Drag&Drop your camera over here from the inspector.
private Vector3 v3_Force; // Force reference vector.
public float f_Multiplier; // A multiplier value if the force wouldn't be enough.
public GameObject carryact;
public Transform ball;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if(carryact.activeInHierarchy)
{
if (Input.GetMouseButtonDown(0))
{
v3_Force = t_Camera.forward;
ball.GetComponent<Rigidbody>().AddForce(v3_Force * f_Multiplier, ForceMode.Force);
}
}
}
}
Comment
Best Answer
Answer by sean244 · Jan 11, 2019 at 12:12 AM
Add this code to the beginning of update
if (Time.deltaTime == 0f)
return;
Your answer
Follow this Question
Related Questions
How to aim a ball with cross hair? 2 Answers
Hover Over Input Field Before Inputting? 2 Answers
Why object goes sometimes through walls by adding force ? 2 Answers
Rigidbody only moving in one direction 2 Answers
Lock OnScreenStick to just the Y axis. 0 Answers