Hello everyone, I am back from a Unity hiatus, but I am having a very strange problem.
Apparently when I run my code in Unity, everything works fine and dandy, but when I run it through the executable, it breaks. I have tried this on my computer, and have sent it over to my friend only to achieve the same results.
What is supposed to happen is:
- Click on the ball.
- If mouse is held down → ball moves with mouse
- If mouse is up → ball is released
This all works in the editor, but when I run it, it goes
- Click on ball, nothing happens
- Move the ball by colliding with it, click on ball, sometimes works
- If mouse is up → ball is released
- If mouse is down anywhere except on the ball, the ball is teleported to you.
I don’t see how this would happen seeing as the code is exactly the same.
enum Weapon
{
None = 0
};
Rigidbody carriedObject;
Weapon weapon = Weapon.None;
// Use this for initialization
void Start () {
//Screen.lockCursor = true;
}
// Update is called once per frame
void FixedUpdate () {
if (Input.GetButtonDown("Fire1"))
{
if (weapon == Weapon.None)
{
RaycastHit outInfo;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out outInfo, 35, 1 << 8))
{
outInfo.transform.position = outInfo.point;
carriedObject = outInfo.rigidbody;
outInfo.rigidbody.position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Input.mousePosition.z + 20));
outInfo.rigidbody.velocity = new Vector3(0, 0, 0);
}
}
}
if (Input.GetButton("Fire1"))
{
if (carriedObject != null)
{
carriedObject.position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Input.mousePosition.z + 20));
carriedObject.velocity = Vector3.zero;
}
}
if (Input.GetButtonUp("Fire1"))
{
carriedObject = null;
}
}
}
Maybe I am overlooking something, but I’m pretty sure everything is right (considering how it works in the editor).
Any help is appreciated!
(I’d upload the rar, but I keep getting upload failed).