- Home /
Calling function from separate script doesn't work
Getting ready to tear hair out.
This is on my main MouseLook script.
public void ApplyRecoil (float amount)
{
Debug.Log ("Called Recoil");
mouseDelta.y += amount;
}
Then I'm trying to call the same function from a different script on my player object.
//Recoil
cam.GetComponent<MouseLook>().ApplyRecoil(recoil);
And it calls the Debug.Log saying "Called Recoil" but doesn't modify mouseDelta.y at all. I've never had anything like this happen, I feel helpless. As this should just WORK.
Here's a quick checklist.
Yes I have set my "recoil" variable.
Yes I have tried calling the function in the same script, and it works just fine.
Yes I am confused.
So if you Debug.Log(mouseDelta) before and after the +=amount, you get the same output?
Yes, the output is the same, calling it from the same script, or from a separate script, the output is the same.
This might be naive (if not stupid), because you might have gotten an error, which you have not reported here, but isn't mouseDelta.y readonly? Try having a global variable which you increase by amount+mouseDelta.y and check if the problem persists.
Even if it were, why would the function work properly on the main script, but not when called from another script?
See you got me confused there. In the main post you are saying that it works on the same script, but in a reply below that you are saying
"Yes, the output is the same, calling it from the same script, or from a separate script, the output is the same.".
Your answer
Follow this Question
Related Questions
Having code fire once in update function? 2 Answers
unity var please 1 Answer
IEnumerator problem 1 Answer