So I’m trying to create a game using UFPS and my code works fine for a few days, the just stops working correctly all of a sudden. I haven’t changed any of the code or anything, it just stops functioning correctly. I was wondering if anyone knows why this happens. Like for instance, I made a wall move by -11 unity units in the x direction. But then one day it stopped working correctly and moved to about -20 or so unity units. So instead of -11 I changed it to -6.7f to get my original state. I’m not sure why my code keeps messing up after a few days it makes no sense.
You’ll need to provide more information - how are you moving the wall by “-11” units?
I think it is VERY unlikely that unity is “messing up your code”, give us some detailed information and we may be able to help.
any errors in console?
you should use version control, so you can compare any changes that has happened,
like this…
if (other.gameObject.name == “Crouch Divider Trigger”)
{
Movement.transform.Translate(-3.8f, 0, 0);
}
And now all the UI menus and Shooting mechanics are messed up as well. It was working fine about an hour ago too and I haven’t messed with anything in the code for those things. All ive done for the past hour is add another script to enact some GUI text so I’m not sure why everything is messed up. A few days ago my project settings got reset as well out of nowhere too.
No I’m not getting any errors in the console. Just the code is working like it used did before
Sorry but that’s still not enough context. Where is that code being called? WHat is ‘Movement’, what is “other”, etc…
Are these uGUI objects? 3d objects? etc, etc.
We’d need all the details to have much chance of helping.
Note, Translate, moves a direction “relative to the objects current location”.
Here is a script that isn’t working anymore. The cursor doesn’t appear, clicking doesn’t work, and the reticle doesn’t go away. Like I said, this was working no longer than an hour ago. If you need anything else I can try to provide as much as I can. thanks for trying to help
3074239–231227–UIMenus.cs (4.64 KB)
Are all those GameObject uGUI items?
If so, have you changed any anchoring etc of any objects? Changed the screen resolution (in the Editor) etc?
They’re just normal UI elements attached to the canvas. I haven’t changed anything about them at all, just added a script to a camera GameObject. The problem may have started after my scripts were reloaded but I don’t know for sure. I’ve tried closing visual studio, re-reloading the scripts, and restarting Unity and it is still broken. It’s just bizarre that it happened so suddenly when it originally worked.
Right, UI elements (uGUI) are not normally moved by using translate or the Transform at all. UI elements have a RectTransform and should be moved using that instead. Things like anchoring, pivot, etc all influence how a RectTransform will behave when moving it.
If you haven’t already, it may be a good idea to work through the uGUI tutorials, they’ll explain how to deal with RectTransforms.
I used Translate on a 3D Cube GameObject not the UI element. Sorry for the confusion. I just wanted to show you the script I’m currently having issues with. Which is that UI menu one. I fixed the Translate one by just changing the numbers to something different. But the UI Menus script isn’t functioning as it should. Like at about 2 hours ago the menus worked flawlessly. When they were opened and the cursor appeared while the reticle was hidden. Now the opposite is happening and I haven’t touched the code. The code just stopped working correctly.
3074264–231231–UIMenus.cs (4.64 KB)
I’ve seen others with a similar problem say just try importing everything into a new project. Maybe that would help.
could be your public variables have changed (resetted to default values) too… if you have moved scripts etc.
How would I go about fixing that?
you need to set them in inspector, like maybe ‘locked’ should be on by default?
Well the booleans are initialized in the start function
Ok so this is the code that is messing up my entire game. Is there any easier way to create pause menus?
using UnityEngine;
using UnityEngine.SceneManagement;
public class UIMenus : MonoBehaviour
{
public bool locked = false;
public bool dead = false;
public bool success = false;
public bool bombsArmed;
protected vp_FPPlayerEventHandler m_Player = null;
protected vp_FPCamera m_Camera = null;
protected vp_FPInput m_Input = null;
protected BombArming m_BombArming = null;
protected vp_SimpleCrosshair m_SimpleCrosshair = null;
[SerializeField]
GameObject pauseMenu;
[SerializeField]
GameObject pauseControls;
[SerializeField]
GameObject mainMenuQ;
[SerializeField]
GameObject restartMenuQ;
[SerializeField]
GameObject quitMenuQ;
[SerializeField]
GameObject deathMenu;
[SerializeField]
GameObject successMenu;
void Start()
{
// m_BombArming = gameObject.AddComponent<BombArming>();
m_Player = GameObject.FindObjectOfType(typeof(vp_FPPlayerEventHandler)) as vp_FPPlayerEventHandler;
m_Input = GameObject.FindObjectOfType(typeof(vp_FPInput)) as vp_FPInput;
m_Camera = GameObject.FindObjectOfType(typeof(vp_FPCamera)) as vp_FPCamera;
m_SimpleCrosshair = GameObject.FindObjectOfType(typeof(vp_SimpleCrosshair)) as vp_SimpleCrosshair;
m_BombArming = GameObject.FindObjectOfType(typeof(BombArming)) as BombArming;
pauseMenu.SetActive(false);
pauseControls.SetActive(false);
mainMenuQ.SetActive(false);
restartMenuQ.SetActive(false);
quitMenuQ.SetActive(false);
deathMenu.SetActive(false);
successMenu.SetActive(false);
dead = false;
success = false;
m_SimpleCrosshair.Hide = false;
}
//Summary
//Checks if the player has clicked the pause button
//opens the pause menu as long as the death menu or success menu isnt open
//and allows for the cursor to be moved freely when the menus are active
//Summary
void Update()
{
if (vp_Input.GetButtonDown("Pause") && !dead && !success)
{
locked = !locked;
m_Player.Pause.Set(!m_Player.Pause.Get());
vp_Utility.LockCursor = false;
if (locked)
{
m_SimpleCrosshair.Hide = true;
Cursor.visible = true;
m_Player.InputAllowGameplay.Set(false);
m_Camera.SetState("Freeze", true);
m_Input.MouseCursorForced = true;
pauseMenu.SetActive(true);
}
else
{
m_SimpleCrosshair.Hide = false;
m_Player.InputAllowGameplay.Set(true);
m_Camera.SetState("Freeze", false);
m_Input.MouseCursorForced = false;
Cursor.visible = false;
pauseMenu.SetActive(false);
pauseControls.SetActive(false);
mainMenuQ.SetActive(false);
restartMenuQ.SetActive(false);
quitMenuQ.SetActive(false);
}
}
if (dead == true && !success)
{
vp_Utility.LockCursor = false;
m_Input.MouseCursorForced = true;
Cursor.visible = true;
}
if(success == true && !dead)
{
vp_Utility.LockCursor = false;
m_Input.MouseCursorForced = true;
Cursor.visible = true;
m_Player.InputAllowGameplay.Set(false);
m_Camera.SetState("Freeze", true);
}
if (m_BombArming.Bomb1Armed
&& m_BombArming.Bomb2Armed && m_BombArming.Bomb3Armed)
{
bombsArmed = true;
}
Debug.Log("Success is: "+ success);
Debug.Log("Bombs Planted = "+ bombsArmed);
}
//summary
//Checks if player dies
//And opens the death screen
//summary
public void Die()
{
dead = true;
deathMenu.SetActive(true);
}
//summary
//Checks if player is in the success trigger and all bombs have been planted
//And sets the success menu as active
//summary
public void OnTriggerStay(Collider other)
{
if (other.gameObject.name == "MissionGameSuccess" && bombsArmed)
{
success = true;
successMenu.SetActive(true);
m_SimpleCrosshair.Hide = true;
}
else
{
m_Player.InputAllowGameplay.Set(true);
m_Camera.SetState("Freeze", false);
m_Input.MouseCursorForced = false;
Cursor.visible = false;
m_SimpleCrosshair.Hide = false;
}
}
}