Trigger not working properly. Need Help.

I’m attempting to have it so when I scroll up and down, it will push or pull a ball when the player controller is near it. The problem I’m having is that it is working all the time whether or not I’m in the trigger area which is attached to the ball. What’s weirder is that When I had it set to be done using left click to push and right click to pull it worked as intended, but then i switched it to the scroll wheel and the trigger stopped working. Here’s the full script:

public GameObject Ball;
public GameObject Camera;
public GameObject Body;
private Transform Force;
public float PushPower = 1;
public float PullPower = -1;

void SetinitialReferences()
{
    Force = transform;
}

void OnTriggerStay()
{
    if (Input.GetAxis("Mouse ScrollWheel") > 0f) Ball.GetComponent<Rigidbody>().AddForce(Body.transform.forward * PushPower, ForceMode.Impulse);

    if (Input.GetAxis("Mouse ScrollWheel") < 0f) Ball.GetComponent<Rigidbody>().AddForce(Body.transform.forward * PullPower, ForceMode.Impulse);
}

Any Help? Thanks in Advance! :smiley:

Go in Edit / Project Settings / Input and look if the axe “Mouse ScrollWheel” is set in the inspector.
If not, set it like this:

81534-unityinput.jpg

You must use a collider to make something trigger. First of all, check on your inspector if you enable IsTrigger on your collider, then try call your collider on your trigger function:

private bool triggered;
     void OnTriggerStay(Collision coll){
             if (coll.gameObject.CompareTag("LiftableItem"))
                  triggered = true;
             else
                  triggered = false;
            }

Then try make a listenner on your imput:

     void FixedUpdate () {
                 if (Input.GetAxis("Mouse ScrollWheel") > 0f  && triggered)           

    Ball.GetComponent<Rigidbody().AddForce(Body.transform.forward*ShotPower,ForceMode.Impulse);

                 if (Input.GetAxis("Mouse ScrollWheel") < 0f  && triggered) 

    Ball.GetComponent<Rigidbody>().AddForce(Body.transform.forward * PullPower, ForceMode.Impulse);
             }