Need help with code please!
Hello,
I have a script of the following, that currently does the action of , when the focus key of 'spacebar', is pressed, locate the camera the players position. The only problem is, is that it only goes to the position for that one frame. Is is possible to help me with writing a true/false statement, or something else, so that when the focus key is pressed, it stays on the player until space is pressed again. if possible of course.
Any questions let me know! Much appreciated!
[Client]
protected override void UpdateClient() {
// pressing/holding space bar makes camera focus on the player
// (not while typing in chat etc.)
if (isLocalPlayer) {
if (Input.GetKey(focusKey) && !UIUtils.AnyInputActive()) {
// focus on it once, then disable scrolling while holding the
// button, otherwise camera gets shaky when moving cursor to the
// edge of the screen
Camera.main.GetComponent<CameraScrolling>().lerpto(transform.position);
Camera.main.GetComponent<CameraScrolling>().enabled = false;
} else {
Camera.main.GetComponent<CameraScrolling>().enabled = true;
}
}
Answer by ju_my · Nov 27, 2018 at 07:18 PM
if i understand well what you want, you can try:
bool focus;
[Client]
protected override void UpdateClient() {
if((Input.GetKeyDown(focusKey) && !UIUtils.AnyInputActive())
focus = !focus
if (isLocalPlayer && focus) {
Camera.main.GetComponent<CameraScrolling>().lerpto(transform.position);
Camera.main.GetComponent<CameraScrolling>().enabled = false;
}
else
Camera.main.GetComponent<CameraScrolling>().enabled = true;
}
Your answer
Follow this Question
Related Questions
Issue with loading scenes with buttons 1 Answer
Problem with checking multiple objects are active. 1 Answer
Camera Jitters When Displacing and Rotating Smoothly 0 Answers
Smoth LookAt Unity c# 0 Answers
Camera drag move 0 Answers