#Error building game
1 messages · Page 1 of 1 (latest)
BallMove.cs
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;
public class BallMove : MonoBehaviour
{
Rigidbody2D rb;
public int initialSpeedX = 8;
public TMP_Text pointText;
public Vector2 InitialPosition = new Vector2(0f, 2f);
public TMP_Text RestartText;
int Point = 0;
int MaxPoint = 0;
bool GameEnded = false;
void Awake()
{
rb = GetComponent<Rigidbody2D>();
}
public void Reset()
{
rb.linearVelocity = new Vector2(Random.Range(-initialSpeedX, initialSpeedX), 0);
rb.position = InitialPosition;
if (Point > MaxPoint)
{
MaxPoint = Point;
}
Point = 0;
pointText.text = $"point: {Point} (Max: {MaxPoint})";
RestartText.color = new Color(1f, 1f, 1f, 0f);
}
void Start()
{
Reset();
}
void Update()
{
if (GameEnded && Keyboard.current.spaceKey.isPressed)
{
GameEnded = false;
Reset();
}
}
public void EndGame()
{
GameEnded = true;
RestartText.color = new Color(1f, 1f, 1f, 1f);
}
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.transform.CompareTag("Player"))
{
Vector2 velocity = rb.linearVelocity;
velocity.x += Random.Range(-7f, 7f);
rb.linearVelocity = velocity;
Point++;
if (Point > MaxPoint)
{
MaxPoint = Point;
}
pointText.text = $"point: {Point} (Max: {MaxPoint})";
}
}
}
send it with the code links under the large code block section
yes
nothing here should cause an error like that. Hmm maybe a longshot but try and get unity to recompile, just add a blank line and go back to unity.
Or possibly restart computer and try again
i was testing something with building a game anyways, put those scripts in just as a sanity check and it builds fine.
The only other thing I could think is maybe you have some packages that are causing issues
Ok. I'll restart my laptop and let you know the result.
Umm... but I made this code last night and already restarted.
I'm not sure this will work but I'll try
its not related to your code anymore, this is clearly either some issue with unity or a package
Yes... I think so...
I dont have all that much time but I think the best things to try here is
restarting,
see what packages you have installed, maybe there is some conflict,
close unity, delete the library folder, and reopen the project
i built my game with an intentional error, trying to use unityeditor code in a build, and this is how it shows in the logs
though this also does show in my console
This makes me so overwhelmed ðŸ˜
another problem occured...
and my all gameobjects are gone
What did I mistake? ðŸ˜
Should I consider to redownload Unity?
Oh, I exited Unity Hub, deleted /library, and opened it again. Then Something started to be redownloaded.
All thing came back. But I can't build...
possibly. this isnt really something ive seen before truthfully.
Maybe make a new project, put a cube in the scene, and just try to build that. I think this is either an issue with some package, or maybe unity got messed up when installing/creating the project
Creating a project is relatively quick at least, id try making a new one before reinstalling the editor
Ok. I'll give it a try
given the warnings, its really likely the project was just corrupted in some way
its hard to say really what the issue is since first it wasn't building for some unknown reason. Maybe that error was hidden deep in the editor log unless you went through it all. Regardless this still shouldnt happen
deleting the library folder is safe because as you saw, unity rebuilds it
I went right. There's no error in building a new project with just one square object.
I think when unity tried to delete something, I pressed no button in the dialog at that time. Just once, and I deleted Library folder and pressed yes then. Maybe something should've been deleted automatically but I denied it, so it made error? I'm not sure...
result.
im not really sure what you mean by this, deleting the library folder isn't done inside unity. you'd also have unity closed before doing it
Yea most likely the project was just corrupted then. Are you using version control?
Hmm, I mean I did something and unity tried to delete something(I think not library folder) and, but I said no. I'm not sure this is the reason.
I did delete library folder while unity is closed.
No, I don't know how to, and I thought "this is just small test project and I don't need that." But ðŸ˜
thankfully it is a small project but yea id truthfully just move on from the corrupted one then. u should always use version control (git)
Should I do something when moving script from current project to new one? I would move on as you said and learn how to use git. Thank you for your help, although I'm not good at English 🥲
moving a script file shouldnt really be an issue. the safest way usually when dealing with files is doing stuff in unity. Though not sure if that works between 2 different projects. This would apply more to renaming files
Either way all unity has to do here is generate the .meta file
Would create empty script in new project and copy codes be the best solution?
for this it really shouldnt matter
i think this was more just being unlucky, or some package issue, rather than anything you did